Search This Blog

Wednesday, July 14, 2010

Using ZendFrmaework for sharing hosting

Here's a short tip for those who need to publish a Zend Framework project on a shared hosting. The typical project structure for a Zend Framework project is something like this:
view sourceprint?
1.projectname/
2. application/
3. controllers/
4. views/
5. scripts/
6. library/
7. public/
8. tests/

The public directory contains all the files that should be directly accessible via the web server, so you must set your web server's document root to this directory.
The problem is, in most shared hosting setups you can't change the document root, and the root directory of your account (i.e. the uppermost level you see when you connect via FTP) is the public document root.

To solve this problem without changing the above directory structure, you can remove the .htaccess file from the public directory, and place this one in the root directory instead:
view sourceprint?
01.RewriteEngine On
02.
03.RewriteRule ^\.htaccess$ - [F]
04.
05.RewriteCond %{REQUEST_URI} =""
06.RewriteRule ^.*$ /public/index.php [NC,L]
07.
08.RewriteCond %{REQUEST_URI} !^/public/.*$
09.RewriteRule ^(.*)$ /public/$1
10.
11.RewriteCond %{REQUEST_FILENAME} -f
12.RewriteRule ^.*$ - [NC,L]
13.
14.RewriteRule ^public/.*$ /public/index.php [NC,L]

This is an effective way to "move" the document root up one level to the public directory.
Source:http://www.alberton.info/zend_framework_mod_rewrite_shared_hosting.html

No comments:

Post a Comment