Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Framework 2 without Vhost configuration

I had finished my first web application using Zend Framework 2 and I'm about to put it online. But may web host doesn't allow me to change my vhost configuration! The .htaccess file is allowed.

So my question is: How to set up my ZF2 app with only .htaccess files?

like image 455
Vinicius Garcia Avatar asked Dec 12 '22 21:12

Vinicius Garcia


1 Answers

Assuming you have a standard ZF2 application based of the skeleton, then try creating a .htaccess file in the root with this in it:

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]

I haven't tested this, but in theory, this should effectively move the document root to the public directory while keeping it out of the url.

like image 173
Rob Allen Avatar answered Dec 26 '22 10:12

Rob Allen