Soroush Rabiei
Soroush Rabiei

Reputation: 10868

Apache virtual host on a specific directory

I need my site to have a virtual host on a specific directory for my zend application. When user enters www.example.com it should go to normal document root but when user navigates to www.example.com/cms it should go to /var/www/cms/public which its .htaccess file is like this:

SetEnv APPLICATION_ENV development

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

On localhost I added this lines to /etc/apache/httpd-vhosts.conf:

NameVirtualHost *:80
<VirtualHost  *:80>
   DocumentRoot "/var/www/cms/public"
   ServerName persian_literature
   # This should be omitted in the production environment
   SetEnv APPLICATION_ENV development
   <Directory "/var/www/cms/public">
       Options Indexes MultiViews FollowSymLinks
       AllowOverride All
       Order allow,deny
       Allow from all
   </Directory>
</VirtualHost>

Now http://localhost/ goes to /var/www/cms/public and every thing works. My question is how should I change change above code, to force http://localhost/ to be the normal directory root (so I could use other applications) and http://localhost/cms to be the virtual host?

Upvotes: 1

Views: 696

Answers (2)

Drizzt321
Drizzt321

Reputation: 1021

Maybe a symlink (symbolic link)? You still should have the entry of course. And you'll have to put in the config (vhost config I think, maybe .htaccess) that apache should follow the symlink.

Upvotes: 0

Marc B
Marc B

Reputation: 360672

A virtual host is done at the hostname/domainname level, not at a directory level. You can use an alias to point the URI /cms to some other directory on your server by putting

Alias /cms /var/www/cms/public

in a .conf file (this will not work in .htaccess)

Upvotes: 3

Related Questions