Routing requests to index.php with Apache


Posted by Andrew McCombe on Mon Mar 25, 2013

Routing requests to index.php with Apache

Here’s how to go about routing requests to index.php with Apache. I’m always having to search for this online so I thought I’d document it here. Many of the ‘modern’ PHP applications use index.php as a router, including WordPress, Drupal, Zend Framework, Silex etc.

Using Mod_Rewrite

If you are using Apache pre-2.5 then your only option is to use mod_rewrite to route requests to index.php:

Using the FallbackResource Directive

From Apache 2.5 onwards you can use the new FallbackResource Directive:

Documentation for this is available at http://httpd.apache.org/docs/trunk/mod/mod_dir.html#fallbackresource.