.htaccess, document root and Zend Framework
It’s funny but I couldn’t find anyone having this issue. It certainly isn’t limited to Zend Framework, it affects everyone who doesn’t have access to apache configuration and wants to have document root in a deeper directory. Maybe I just can’t google very well.
Imagine a shared host. You can’t choose your document root, it’s firmly set to one particular directory. Now you want to install Zend Framework. Imagine you’d like to follow the standard directory structure (that means you more or less have these directories in your project: application (the application), library (zend and other libraries) and public (stuff accessible from the outside, images, css etc.)). Normally, you’d want to point your document root to the public directory, but when you can’t do that you can use .htaccess in the project directory to redirect everything to public.
RewriteRule !\.(js|gif|jpg|png|css|txt)$ public/index.php [L]
RewriteRule ^(.*)$ public/$1 [L]
This was the first thing I wrote, and it works on certain servers. Other servers will kindly remind you that “Request exceeded the limit of 10 internal redirects due to probable configuration error.” Which kind of makes sense when you think about it. Makes me wonder how comes the above code actually worked on two different configurations.
Now here’s the code that works (and in my humble opinion it also should work, as opposed to the one above):
RewriteRule !\.(js|gif|jpg|png|css|txt)$ public/index.php [L]
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ public/$1 [L]
And finally a disclaimer: I am not sure about the security implications. If someone knows more about possible security issues with this, please do leave a comment.












Anonymous wrote:
Michael Goetze wrote:
Why on earth would you want to install Zend Framework?!?
Anyway, I suspect your first try at rewriting works with Apache 2.2 but not Apache 2.0, however, I’m too lazy to test it.
Amin wrote:
Hi, Your solution is really effective but i test it in different aspect and failed in some point. for example BaseUrl access with this solution isn’t possible and you couldn’t access to image folder in include in some of servers.
Thanks.
Brian wrote:
Ah, thanks for that. I was having a redirect problem w/ ZF as well. This wasn’t the exact problem, but it remind me to look at my .htaccess, which I’d forgotten to update when I moved my project files around
Richard Knop wrote:
Here is imho a better solution for this issue:
http://www.alberton.info/zend_framework_mod_rewrite_shared_hosting.html
Regards,
Richard
tasuki wrote:
Thanks, Richard — that solution is definitely better as it doesn’t rely on a list of file extensions.