Redirect All Requests To Index.php Using .htaccess

In one of my pet projects, I redirect all requests to index.php, which then decides what to do with it:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

This snippet in your .htaccess will ensure that all requests for files and folders that does not exists will be redirected to index.php.

This enables the rewrite engine:

Options +FollowSymlinks
RewriteEngine on

This checks for existing folders (-d) and files (-f):

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

And this does the actual redirecting:

RewriteRule . index.php [L]

If it's not working, make sure that mod_rewrite is installed on Apache

My name is Jurgens du Toit. I love web development and anything internet related. This is my home site and playground.

Follow me on Twitter. Now.   Find me on Facebook.
myScoop