TomNomNom.com

Blogging since 2008 until 2010

Using mod_rewrite to redirect all requests to a page

I always forget how to do this, so I thought I would write it down somewhere.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?request=$1

When in a .htaccess file (provided AllowOverrides is enabled) this will redirect all requests that don't match a physical file to /index.php, passing the request into the $_GET['request'] variable.

If you miss out the second line: you will get a 500 internal server error as your response because the request to /index.php would redirect to itself.

First posted: Wed, 04 Aug 2010 10:20:49 +0000