Jump to content
Larry Ullman's Book Forums

Chap 17 Message Board - Url Rewrite


Recommended Posts

Hi Larry and forum members,

 

I really enjoyed and learned a lot from this book. I built many of the projects on my localhost. I really liked the message board presented in chapter 17. I am trying to add features to this, such as a profile page and even a basic photo gallery.

 

I have a question about URL rewrite. I would like for users to be able to access their profile page with -  example.com/johndoe  -  Currently it is   -  example.com/profile.php?user=johndoe  -  I understand how to  use .htaccess to shorten URLs. I know how to change  -  example.com/profile.php?user=johndoe  -   into  -   example.com/profile/johndoe     But how do you change it to -  example.com/johndoe ?

 

I have been looking at the features of every social network and forum I could find, and I have seen this feature available.  On  tagged.com  you can choose your own profile URL and then access it with -  tagged.com/tomhp1

 

Also, I work for a school that has a CMS that allows you to create “web address mappings.”   If we have our Elementary music department at  -  school.edu/site/Default.aspx?PageID=76 -  I can choose a name like ElemMusic  and map it to that page.  We can then access that page with -  school.edu/ElemMusic -  How is this possible?  Can this be done with PHP?

 

I have been searching for information about this, but I haven’t been able to find anything about the examples above. Can you or one of your readers tell me what type of technique or technology is being used?  I’m not asking for finished code, just a pointer in the right direction.

 

Thanks for whatever guidance you can provide - Tom.

Link to comment
Share on other sites

Hello. Thanks for the nice words on the book. I really appreciate it! I'd strongly caution against ever using someurl.com/something as an acceptable format. It'll be really really hard to differentiate between rewrites and actual files and folders that exist in the top of the website (e.g., someurl.com/page.php or someurl.com/image/). Also, if you wanted to redirect all pages to someurl.com/somepage and redirect all user home pages to someurl.com/someperson, that will be complicated and messy, too. Instead, use something like someurl.com/people/someperson and use someurl.com/somepage *only if* all pages are virtual. Otherwise, put pages in a subfolder, to (e.g., someurl.com/page/somepage). 

 

As for Facebook, it can do facebook.com/someuser because *all* Facebook pages are user profile pages. Your CMS would not have that. To put a finer point on this, if you put all pages and users in the same directory, how would you know if someurl.com/phpmaster is a page or a user profile?

 

As for your school, since it uses ASP for the site, you cannot use PHP to do the URL rewrites. (To be clear, you don't use PHP for URL rewrites on PHP-driven sites, either; you use Apache or whatever web server). I assume the site is using IIS as the web server. I don't know if it supports URL rewriting--I would assume it would, but I have no idea what or how to approach it. It looks like you'd use this: http://www.iis.net/downloads/microsoft/url-rewrite

 

More than anything, when you go down the path of doing rewrites for an entire site, you need a big, long-term picture in mind. You don't want to put something in place, have it being used, and then realize there are conflicts, requiring messy redirects and new plans to fix. Text URLs are nice and all, but don't do it just to do it. Have a very clear, long-term justification and plan in place. 

Link to comment
Share on other sites

 Share

×
×
  • Create New...