虚拟主机映射到目录结构 [英] virtual hosts map to directory structure

查看:135
本文介绍了虚拟主机映射到目录结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读Apache的群众虚拟主机的帮助,但作为一个相对的新手,我留下了一点困惑。我知道我的问题一定是acheiveable,因为它是一个pretty基本的问题,但我失去了...

I have read the mass virtual host help on apache but as a relative newbie I am left a little confused. I know my problem must be acheiveable as it is a pretty basic problem but i am lost...

基本上我有很多指向我的服务器,他们指出他们的DocumentRoot是一致的文件结构...虚拟主机例如..

Basically I have lots of virtual hosts pointing to my server and the file structure that they point to for their DocumentRoot is consistent... e.g..

www.mydomain.com -> /home/blah/vhosts/mydomain.com/www/public
abc.mydomain.com -> /home/blah/vhosts/mydomain.com/abc/public

www.another.co.uk -> /home/blah/vhosts/another.co.uk/www/public
def.another.co.uk -> /home/blah/vhosts/another.co.uk/def/public

如果可能的话,我也需要重定向非www *到www *,但考虑到子域名的可能性,从而使:

If possible, I also need to redirect non-www.* to www.* but taking into account the possibility of a subdomain, so that:


  • mydomain.com 将被重定向到 www.mydomain.com

  • abc.mydomain.com 不会重定向到 www.mydomain.com 因为它是
    与上述定义处理(由于目录结构)

  • mydomain.com is redirected to www.mydomain.com
  • abc.mydomain.com is NOT redirected to www.mydomain.com as it is handled with the definition above (due to directory structure)

这是在所有可能的?

推荐答案

下面我为我所有的虚拟主机做什么:我使用的阿帕奇writemap

Here what I do for all my vhosts: I'm using Apache writemap.

像这样的合作伙伴创建一个新的partner.txt文件:

Create a new "partner.txt" file with partners like this:

0 www
1 partner1
2 partner2
3 partner1

然后编译它,使用添加到您的规则集以找出preFIX是否是合作伙伴或没有,像这样的:

Then compile it, and add use it into your rewriterules to find out whether the prefix is a partner or not, like this:

<VirtualHost *>
    ServerAdmin webmaster@mydomain.fr
    DocumentRoot "/web/htdocs/olivier/mydomain.fr/dev/website"
    ServerName mydomain.fr
    ServerAlias *.mydomain.fr
    ErrorLog "/web/logs/mydomain.error.log"
    CustomLog "|/opt/httpd/bin/rotatelogs /web/logs/mydomain.fr/access_log.%Y-%m-%d-%H_%M_%S.log 5M" combined
    ErrorDocument 404 /404.php

    RewriteEngine On
    # trying to hack = redirect:
    RewriteRule (.*)setup.php http://disneyland.fr/ [NC,R,L]
    RewriteRule (.*)admin(.*) http://disneyland.fr/ [NC,R,L]

    # if your host doesn't begin with "www" add it and redirect:
    RewriteCond %{HTTP_HOST} ^mydomain\.(fr|com|net|org|eu) [NC]
    RewriteRule (.*) http://www.mydomain.%1$1 [QSA,R=301,L]

    RewriteMap partners \
      dbm:/web/htdocs/olivier/mydomain.fr/rewriterules/partners.map

    # test if known partner:
    RewriteCond %{HTTP_HOST} (([a-zA-Z0-9\-]+)\.)mydomain.com$
    RewriteRule (.*) - [QSA,E=PARTNER:${templates:%1|notfound}]

    # if partner not found or empty, 404:
    RewriteCond %{ENV:PARTNER} ^$ [OR]
    RewriteCond %{ENV:PARTNER} notfound
    RewriteRule .* - [R=404,L]
</VirtualHost>

这篇关于虚拟主机映射到目录结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆