Dynamic URL rewriting with .htaccess

I was upgrading some old page with new CMS that supported nice and friendly URLs. I didn’t want to loose all those precious links to page content so I tried to make redirects with .htaccess. As I soon realized this is not so trivial as I thought.

My old links were dynamic like “index.php?id=12”. If they were static without question mark and followed by query string everything would be trivial since there are tons of examples all over the net.

But in my case (look below) examples found on the net wouldn’t work.

Finally I managed to get things done with conditional rewrite like this

If you need to strip the query string from the url, simply put “?” after redirect url like this

btw. I would like to state that I’m not mod_rewrite expert. So if anybody knows better way to do this, please let me know 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

Please prove me that you are not spamer :) * Time limit is exhausted. Please reload CAPTCHA.