mod_rewrite made easy

by Alexander Vassbotn Røyne

13:07:14 Tuesday, August 08 2006

mod_rewrite made easy

published: 13:07:14 Tuesday, August 08 2006, updated: 18:55:07 Tuesday, August 08 2006, modified: 14:51:09 Friday, September 05 2008

mod_rewrite made easy

Lately I've been trying to make all my links to look so pretty that even art critics could say something nice about them, and to make it easier for visitors to remember my links. And believe me, it is actually easier than it seems.

How? Well, the solution to this problem was the use of mod_rewrite us flag. I am not going to explain to you what it is in depth, but basically, it rewrites URI's and also makes it easier for search engines to find your pages. A little tutorial follows.

Instead of using long useless links like:

http://www.phun-ky.net/showpost.php?year=2006&month=08&slug=mod_rewrite_easy

You can make it look so much better with mod_rewrite, like this:

http://phun-ky.net/2006/08/mod_rewrite_easy

Just by adding these lines in a .htaccess file:




RewriteEngine On
RewriteRule ([0-9]+)/([0-9]+)/(.*)$ showpost.php?year=$1&month=$2&slug=$3
Options +FollowSymlinks
RewriteCond %{http_host} ^www.phun-ky.net [nc]
RewriteRule ^(.*)$ http://phun-ky.net/$1 [r=301,nc,L]

If this was hard or you want to learn more, check out the cheat sheet posted with this post or read this .htaccess tips and tricks us flag.

top

Filed under: How To. Post a comment.
Add to: Digg It Digg, Give kudos to this article! Kudos, Share on Facebook, Slashdot It!
Follow responses to this entry with the RSS feed.

click here to post a comment