Enabling mod_rewrite on Linux server

December 24, 2007

Hi friends I really had a hectic time making the friendly URL run on my Linux Server. Locally being on windows I didn’t had to do much apart from just enabling the “mod_rewrite” option and thats enough to make the friendly URL work on apache installed locally on my machine.

To make it run on Linux you need to make the following changes in the .htaccess file

RewriteEngine On

If you have something like http://www.yourdomain.com/index.php?url=test
or

If you have something like http://www.yourdomain.com/news/test working locally then you need to write the following
in your .htaccess file
- RewriteRule ^([^/\.]+)/?$ /$1.php [L]
$1 -> This refers to the first parameter and it informs the Apache that its a php file and redirects it accordingly.

- RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /$1.php/$2 [L]
$1 -> Refers to “news” in the URL mentioned above.
$2 -> Refers to “test” in the URL mentioned above.

So just keep on increasing the slashes as the number of parameters keep on increasing.
………………..

- RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /$1.php/$2/$3 [L]

- RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /$1.php/$2/$3/$4 [L]

- RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /$1.php/$2/$3/$4/$5 [L]

Hope this help would save your precious time to an extent If yes … leave your comment ..