Just a short one this time. This is something I encountered at work today.

I started a new ZF project in our development environment, which makes use of dynamic virtualhosts. When I started the application for the first time in the browser, I got an internal server error. Of course I didn’t expect this. So I had a look at the apache logs and found entries like this:

[Wed Jul 22 16:00:26 2009] [debug] core.c(3052): [client] redirected from r->uri = /data/virtualhosts/dev/...

After some googling, I found out this has something to do with having apache rewrite rules in combination with dynamic virtualhosts. Then I had a look at an older ZF project on the same server and found a small but significant difference:

Standard .htaccess created by Zend_Tool:

SetEnv APPLICATION_ENV development
RewriteEngine On<br />
RewriteCond %{REQUEST_FILENAME} -s [OR]<br />
RewriteCond %{REQUEST_FILENAME} -l [OR]<br />
RewriteCond %{REQUEST_FILENAME} -d<br />
RewriteRule ^.*$ - [NC,L]<br />
RewriteRule ^.*$ index.php [NC,L]<br />

And here is the last line of the older .htaccess, the rest is identical:

RewriteRule ^.*$ /index.php [NC,L]<br />

Notice the difference? There is a forward slash before index.php in the working .htaccess.

I simply added the forward slash in the non-working htaccess, and everything worked fine!

Note: this may not work for you, as I have seen articles where REMOVING the forward slash was the solution. It is entirely dependent on your specific apache config and more importantly, your apache version. This is because there have been changes in how apache matches redirects in recent releases.