开发者

Multiple versions of a website each with its own root directory using Apache

开发者 https://www.devze.com 2023-02-14 20:47 出处:网络
I have multiple versions of my website. Each resides in its own folder, for开发者_运维百科 example:

I have multiple versions of my website. Each resides in its own folder, for开发者_运维百科 example:

site_v1/  
  index.html  
  page1.html    

site_v2/  
  index.html  
  page1.html  

How can I configure apache so that each version of the site has its own definition of the root directory?

In other words, I want site_v1/index.html to think the root directory is site_v1, and site_v2/index.html to think the root directory is site_v2


You are looking for the VirtualHost directive.

Apache manual on virtual hosts


As @Pekka wrote, you are indeed looking for the VirtualHost directive, but I though I might add an example configuration for your virtual host configuration. This should be placed in your httpd.conf file, edited to your preference, and remember to fill in the full path:

NameVirtualHost v1.yoursite.com:80
<VirtualHost v1.yoursite.com:80>
    ServerName v1.yoursite.com
    ServerAlias v1.yoursite.com
    DocumentRoot /path/to/site_v1
    ErrorLog /path/to/prefered/error.log
    CustomLog /path/to/prefered/access.log combined
    <Directory /path/to/site_v1>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

NameVirtualHost v2.yoursite.com:80
<VirtualHost v2.yoursite.com:80>
    ServerName v2.yoursite.com
    ServerAlias v2.yoursite.com
    DocumentRoot /path/to/site_v2
    ErrorLog /path/to/prefered/error.log
    CustomLog /path/to/prefered/access.log combined
    <Directory /path/to/site_v2>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

If you want, you may chose to use a different access/error log for each version of your site. Just change the name/path to the log file, and you're done. /path/to are the path to the site folder, and v1.yoursite.com & v2.yoursite.com should be changed to the relative domains you want to use for each version. If you don't want to change the log files, remove the ErrorLog and CustomLog directives and I'll default to the main log files set in httpd.conf

0

精彩评论

暂无评论...
验证码 换一张
取 消