Creating a Vanity URL with a htaccess Rewrite Rule

Date May 31, 2009

I’m trying to set up my site so that users can have a “vanity url”.

To do this, I added the following rewrite rule to the htaccess file:

RewriteRule ^([A-Za-z0-9]+)[^.]$ view.html?id=$1 [nc]

Here’s what this does.

If the user goes to http://www.domain.com/vanityurl it will Rewrite the url to view.html?id=vanityurl

If the filename has a dot in it, like .html, .htm, or .php, it will ignore the rule.

Hopefully this helps someone out there on the interwebs.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Furl
  • Ma.gnolia
  • NewsVine
  • Propeller
  • Reddit
  • Slashdot
  • Spurl
  • StumbleUpon
  • Simpy
  • Sk-rt
  • TailRank
  • Technorati
  • TwitThis

Leave a Reply

You must be logged in to post a comment.