I'm writing this up while it's still fresh in my head. Very fresh. As in: I have just lost two hours trying to resolve a problem I was having using Apache's
mod_rewrite within a WAMP stack. Oy.
Fundamentally, I'm not doing anything all that exciting: I have a local WAMP server with a virtual host that I'm using to serve a test copy of a Joomla site I'm working on. For this particular site, we are using Search Engine Friendly URLs. A server-side redirect is required to implement these URLs, which for WAMP means an
.htaccess file (although this could also be done in the Apache config file… Joomla ships with an
.htaccess file though).
I had just about completed spinning up a new instance of the local test site, and one of my final tests was to make sure SEF was working. Unfortunately, when I finally got around to adding a page that would exercise this feature I got a 404 in the browser. I double-checked the filename, checked for stray comments in
.htaccess, re-re-reviewed my virtual host block, etc. Nothing seemed out of whack.
After spending way too much time trying (unsuccessfully) to set some redirect logging, re-start
mod_rewrite, and fiddling around with the Apache config file, I finally stopped for a moment and took stock of the situation.
Oddly, the earlier instance of the site (which I'd left in place) was still working fine, including SEF. Everything was identical. I'm ripping my hair out at this point. How is it possible for two identical setups to behave differently under the same server?
The answer (of course) is that they were not identical.
As I was slowly pouring over files again in a desperate search for some clue, I realized that for the 2nd site instance, I hadn't created a WAMP 'alias'. I'm not exactly sure what these aliases are used for (since I always use a virtual host block along with a '.local' TLD), but in the past I've always created one (mostly so I can resolve local test sites over my LAN without DNS).
So, I updated the existing alias (for site 1) with the new root path for site 2. And just like that, redirection was working properly on site 2, complete with our lovely SEF URLs. Perhaps even more interestingly, site 1 redirects now no longer worked. After adding an new alias for test site 1, those redirects started working again.
If you're an expert sys admin or server geek, you're probably laughing and saying 'Of course they did!'. Or maybe not. I know a bit about this stuff, but I have to admit I'm baffled as to why the alias made such a difference. I suspect that I'm doing something in the alias that I could be doing in my virtual host block which would resolve this, but I'm not sure what. Perhaps when I have some time I'll do a bit more research on it—and if so I'll update this post.
I wanted to write this in part because it was incredibly hard to find any helpful results while searching related to this issue. So for the sake of future searchers, take care when using
.htaccess redirects under WAMP server, or you'll encounter some issues!
Also, what's with the title of this post? Well, many moons ago I was a Clogger. One of the tunes we used to dance to was If You're Gonna Play In Texas… and I guess it just stuck with me! I was young and impressionable!