11 September 2012

enable url rewriting on default linux setup

A few distributions don't have URL rewriting in apache enabled by default. Here is how to turn it on in Ubuntu:

make a symbolic link for the module

cd /etc/apache2/mods-enabled
ln -s ../mods-available/rewrite.load


Enable .htaccess to overwrite server set behavior - edit /etc/apache2/sites-enabled/000-default and change

...
AllowOverride None


to


<Directory /var/www>
...
AllowOverride All


or instead of all, you can allow only whatever you need.

Restart Apache

/etc/init.d/apache2 restart


edit your .htaccess in the folder you are serving you want to enable url rewriting:

RewriteCond on

RewriteCond %{REQUEST_FILENAME} ^.*\.(gif|jpg|png|css|js|ico)$
RewriteRule ^(.*)$ $1 [L]

RewriteRule ^.*$ index.php [L]

This setup forwards any request that is not a resource to a central index.php page.

That's it folks.

No comments: