Using rewrite rules to have a tidy blog

Today, I was playing with apache mod_rewrite and decided to make my blog a little bit tidier. So I created a rule to make all my links looking like: http://emresaglam.com/blog/[storyID].

Since there are many many tutorials on the web on howto use mod_rewrite I`m not going to go into details.

I created an .htaccess file under my web root directory containing these:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^blog/([0-9]+)$ /blog/haber.php?id=$1 [nc]

So it takes any requests in the form of /blog/[a number] and maps it to the url: /blog/haber.php?id=[the number]

This is a basic regular expression.

And I went into my blog code and changed all the links from the haber.php?id=$id to $id only ; )

That simple!

Update: Murat pointed out that actually this wouldn`t work for urls like  /blog/182/ (with a trailing slash) But I already have a rule to redirect the entries with a trailing request with a 301. And then the rules above kicks in. And the rule is:

RewriteRule ^blog/([0-9]+)/$ /blog/$1 [R=301,N]