URL Rewriting
Apache mod_rewrite
Rewriting with VirtualHost
Here is a very basic virtual host definition, with the focus being the rewrite rules. These rules direct all requests to index.php, except specified file types (.js, .ico, etc.):
<VirtualHost my.domain.com:80>
ServerName my.domain.com
ServerRoot /path/to/server/root/
DocumentRoot /path/to/server/root/my.domain.com/www
RewriteEngine off
<Location />
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php
</Location>
</VirtualHost>
Note the forward slash preceeding 'index.php'. These rules differ from .htaccess rules in that respect.
Rewriting with .htaccess
Routing requests
Again, these rules direct all requests to index.php, except specified file types:
RewriteEngine on RewriteBase / RewriteRule !\.(js|ico|txt|gif|jpg|png|css)$ index.php
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:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
You can also simply allow a specified group of files to pass through unaffected by using this line:
RewriteRule ^(foo|bar).* - [L]
In this case, files foo.* and bar.* will be accessed normally.
For more information, see Jayson Minard's Blueprint for PHP Applications: Bootstrapping.
ISAPI_Rewrite for Microsoft IIS
RewriteRule ^[ZFUSER:\w/\%]*(?:\.(?!(?:js|ico|gif|jpg|png|css)$)[ZFUSER:\w\%]*$)? /index.php [I]
To learn more about the ISAPI_Rewrite and its syntax, visit the ISAPI_Rewrite documentation.
Lighttpd
url.rewrite-once = (".*\.(js|ico|gif|jpg|png|css)$" => "$0", "" => "/index.php")