View Full Version : mod_rewrite advice please!

06-28-2011, 10:55 PM
My website uses a CMS which loads page content according to the value of a GET var called "page".

E.g. http://www.mysite.com/index.php?page=mypage will load the content for mypage.

How can I generically mod_rewrite http://www.mysite.com/index.php?page=xxx as http://www.mysite.com/xxx ?

06-28-2011, 11:25 PM
Try something like this (untested):

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?page=$1 [L]

06-30-2011, 08:08 AM
Many thanks for that.

Reading through, I realise I have no idea how it works! Seems I need to familiarise myself with mod_rewrite. Can you recommend a good online tutorial that explains the syntax?

07-08-2011, 11:37 PM
I've always found...


... to be quite a good all round tutorial on mod_rewrite. Combine it with a bit of Regular Expression knowledge and you should be golden.