Apache Rewrite Rules
Views:
Some mod_rewrite recipes
The apache documentation is very good and has an entire guide devote to the magical wonders of mod_rewrite - there is no way I am going to try and compete with that. httpd.apache.org
Pseudo Version Numbers on Files
This is handy if you've set caching settings really aggressively, you can link to the same file, such as an image, with updated contents. Including a version number in the url of the file name and incrementing this version number every time you update the file, will defeat caching proxy servers and browser caches.
This rule applies to Javascript and CSS files; GIF, JPEG and PNG images; as well as flash files. It assumes that you keep all of these in a folder called "assets" in your document root.
The pseudo version number is at the end of the file name, before the file extension and prefixed with the characters "vK" (for Kieran's Version Number)
So the file /asset/css/styles.css could use the url /assets/css/styles.kV1.css and /assets/css/styles.kV2.css
RewriteEngine On
RewriteBase /
# Do not apply the rule if the URL points to a genuine file or folder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# The Rule.....
RewriteRule ^assets/(.+)\.kV[0-9\.\-a-zA-Z]+\.(css|js|gif|png|jpg|swf)$ /assets/$1.$2 [QSA,L]
Friendly URLs
Get rid of the query strings or script file names. Use a virtual URL structure for you application.
This rule takes the URL from the site root and passes it as an argument to your index file.
Your visitors see a URL like www.example.com/foo/blah/pickle while your application is called as www.example.com/index.php/foo/blah/pickle
RewriteEngine On
RewriteBase /
# Do not apply the rule if the URL points to a genuine file or folder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# The Rule.....
RewriteRule ^(.*)$ /index.php/$1 [QSA,L]
