mod_rewrite

If you are using Apache then a great tool is: mod_rewrite (similar third-party tools also exist for IIS, such as: ISAPI_Rewrite). Anyway lets say you have a web-site and you reference pages like this: http://www.mysite.com/detail.php?id=20 if you notice carefully in sites like Amazon, Yahoo and MSN they almost never access a site like this. Instead you will see something like this: http://www.mysite.com/detail/20/. This looks like detail is a folder and so is 20. But that’s just mod_rewrite playing tricks on us.

To achieve this, you have to add the following two lines:

RewriteEngine ON
RewriteRule /detail/([0-9]+)/   detail.php?id=$1

That’s it! mod_rewrite works using regular expressions so the possibilities are endless. For more information check this site out: http://www.sitepoint.com/article/guide-url-rewriting/2 (needless to say the site itself uses mod_rewrite).

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Live
  • StumbleUpon


Leave a Reply