Mar 29 2010

Zend Framework: /public folder redirect

Published by Jose Hidalgo at 3:15 am under Programming, php

If you use the Zend Framework everything is going to work just fine until you have to upload the application, then you realize that your hosting facility is not going to change the Document Root inside apache’s config.

That’s when you have to use the .htaccess to circumvent this situation. Here is one of many possible solutions that works for me:

# Turn On the engine
RewriteEngine on

# Change yourdomain.com to be your main domain, No Case sensitive
RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$ [NC]

#we are redirecting what doesn't have the /public already
RewriteCond %{REQUEST_URI} !^/public/

#if its a file or directory that exists, then just hit it
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#save the url and redirect to it with the '/public' at the begging
RewriteRule ^(.*)$ /public/$1 [L]

#finally if the request goes to the base, show the /public/index
RewriteCond %{HTTP_HOST} ^(www.)?innova.joseche.com$ [NC]
RewriteRule ^(/)?$ public/index.php [L]

No responses yet

Leave a Reply