All examples that follow use mod_rewrite, an official module that comes bundled with Apache. To use it, mod_rewrite must either be included at compile time or enabled as a Dynamic Shared Object (DSO). Please consult the Apache documentation for your version for more information.
Here is a very basic virtual host definition. These rules direct all requests to index.php, except specified file types (.js, .ico, etc.):
Note the forward slash preceeding 'index.php'. These rules differ from .htaccess rules in that respect.
Again, these rules direct all requests to index.php, except specified file types:
Handling file and directory exceptions
These rules (used immediately prior to the RewriteRule above) exclude real files and directories from the rewriting and lets them pass through unaffected:
You can also simply allow a specified group of files to pass through unaffected by using this line:
In this case, files foo.* and bar.* will be accessed normally.
For more information, see Jayson Minard's Blueprint for PHP Applications: Bootstrapping.
A rewriting engine does not come standard with IIS. If you haven't done so already, you will have to download and install one.
Helicon Tech produces the established ISAPI_Rewrite in Full and Lite versions. Currently, Full is $99, while Lite is free; however, Lite constrains you to one httpd.ini file per server.
To enable rewrite support for Zend Framework, simply add the following to httpd.ini:
If your application is contained in a subdirectory, make sure to also set the correct RewriteBase.
To learn more about the ISAPI_Rewrite and its syntax, visit the ISAPI_Rewrite documentation.
IIRF (Ionic's ISAPI Rewrite Filter) is a relative newcomer, having been in development for two years. It supports most of the same features as ISAPI_Rewrite.
For IIRF, do the following:
- Download and extract the files.
- Copy IsapiRewrite4.dll and IsapiRewrite4.ini to C:\Inetpub.
- Edit IsapiRewrite4.ini so it contains the following:
- From the IIS Control Panel, select "Properties" of "Web Sites".
- Browse to the ISAPI Filters tab and click "Add...", then enter "rewrite" for the filter name.
- Browse to C:\Inetpub and double-click IsapiRewrite4.dll
- Click OK.
- The "rewrite" filter should now be listed at the end of the ISAPI filters list.