<!-- Content Here -->

Where content meets technology

Nov 08, 2012

The Case of the Mysterious Redirect

Like most technical people, I have many development environments running on my local workstation.  I use a configuration of Apache virtual hosts and my /etc/hosts file to keep them sorted out.  It normally works great but yesterday I solved a vexing issue and  I thought I would share.

The issue was that whenever I hit a specific development environment, it would redirect me to my blog (http://www.contenthere.net) with a path that was based on the location of the Apache doc root.  I hadn't used this environment in a while and so a lot of things could have caused the problem.  At first I thought it was a DNS issue.  Then I was certain it was an Apache configuration issue.

After trying all sorts of things, I realized that I had accidentally saved some .htaccess file to the root of my home directory.  The doc root of this particular development environment (which was inside my home directory) didn't have its own .htaccess so Apache traversed up the directory structure to find one and applied the rewrite rules within it.  Deleting this file made the problem go away.

I suspect that I accidentally copied the errant .htaccess file from a server by double-clicking on it in my FTP client.  I had no idea that Apache would behave in that way.  I spent ages searching through Apache configurations and the doc root.  I looked into issues that might have been caused when I upgraded to Mountain Lion.  But I didn't look in the root of my home directory until I searched for all of the .htaccess files on my machine.

One thing that I learned from troubleshooting (in addition to .htaccess behavior) was about DNSMasq.  It allows you to create wildcard entries like .dev, which saves a lot of effort editing the /etc/hosts file.  Pretty cool!  So it wasn't a total loss of time.

Hopefully someone will learn from my experience.