I spent a few hours recently trying to debug some Apache Rewrite rules on our development server.
We had a particular directory outside the root of the website that I was using an Alias command to make available. However, within this directory I also wanted to apply a couple of different Rewrite rules.
A simple cachebuster
One of the rules was basically to remove instances of the string nocache_XXXX_
where XXXX
was a number which could change (this is usually a date-stamp, such as 20130131 if modified on 31st Jan, 2013). This allows us to easily change the number in the URL which will force the browser to reload the page, avoiding possible caching problems.
For example:
http://www.example.com/nocache_20130131_js/file.js
will be rewritten as
http://www.example.com/js/file.js
If the file.js changes we can modify the number in the url, which will force the browser to load the JavaScript again as it is a different URL, but the web server will return the current “file.js” inside the “js” directory, after the rewrite rule has been applied.
To cut a long story short, I found out that mod_alias and mod_rewrite cannot be used together. Therefore, the workaround in my case was to use just mod_rewrite and use a symbolic link instead of trying to use mod_alias. Note that to allow symlinks to be use, it is also necessary to specify Options FollowSymLinks
within the Apache config for that site.
Maybe this will help someone else avoid wasting time trying to get mod_rewrite to work on top of mod_alias.