Quick trick for Pretty URLs

April 9th, 2009 by Jack Keller

Most peo­ple uti­lize a CMS or Weblog soft­ware that auto­mat­i­cally han­dles url rewrites, but what if you have a sim­ple web­site that doesn't need quite the same treatment?

I came up with a quick down and dirty lit­tle trick to help over­come such an instance and I think you may find this useful.

Fire up your favorite text edi­tor and open up cre­ate a .htac­cess file (or mod­ify the file that may be sit­ting in your root direc­tory) and paste these lines in. Feel free to tweak them a bit to suit your needs, maybe you'll even find a bet­ter use for this method.

HTML:
  1. RewriteEngine On
  2. Rewrite­Base /
  3. RewriteRule ^admin/.*$ — [PT]
  4. # Use the above line for a folder that you DON'T want to fol­low these rules
  5. RewriteRule ^/?([a-zA-Z0-9-_/]+)/$ $1.php [L]
  6. # Here's where the "magic" happens
  7. # http://www.example.com/page.php — OLD
  8. # http://www.example.com/page/ — NEW

And that's it! Pretty URL's on the easy.

Share?
  • Facebook
  • Design Float
  • del.icio.us
  • StumbleUpon
  • Technorati
  • Digg

Posted in Programming, SEO Be the first to comment! »

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

About media|extranet

We're a group of industry professionals who would like to give a little bit back to the community. Although we've just begun, we plan to do some write-ups on Advertising, Marketing, Development (.NET, PHP, Flash, Flex, AIR, JavaScript Frameworks, etc.) and Copywriting. Visit our contact section if you would like to see us cover something that we're not. The links below are for our writers, visit them directly if you have a project in mind that could utilize their talents.

Visit Snackbox