Zend Framework – All project’s files on DOCUMENT_ROOT
You often have to publish the sites where, on the server, you have write access on the main public directory only, the DOCUMENT_ROOT of the site. This is always (or almost) on shared server. How to solve this problem?
Our goal is to have the same structure of a default Zend Framework in the DOCUMENT_ROOT folder, but allowing the user access only to the public folder. To do this we must create an .htaccess file in the DOCUMENT_ROOT, telling Apache to redirect all requests to the index.php file we have in the public directory.
The contents of the .htaccess file on DOCUMENT_ROOT, which we will use as default .htaccess (the same that you should put on the public folder, which you’ll can delete), will be the following::
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [NC,L]
The first line, as you should know, is to define the type of use (then, the different configurations) of the project.
The other set Apache’s mod_rewrite rules for redirect requests on public folder.