开发者

Apache VirtualDocumentRoot best setting

I want to have a clean, efficient directory setup with VirtualDocumentRoot. (Reference: http://httpd.apache.org/docs/2.0/mod/mod_vhost_alias.html).

In particular, I am thinking of the following:

1) http://example.com to be served by /apache_root/example.com

2) http://www.example.com to be served by /apache_root/www/example.com OR /apache_root/example.com/www OR /apache_root/example.com (any one of these is fine. But I don't want to use redirect for the sake of efficiency).

3) http://abc.example.com should be served by /apache_root/example.com/abc (Basically, it should be directory inside /apache_root/example.com)

Now comes the tricky part::

All of the above can be achieved using the directory name Interpolation methods listed here: http://httpd.apache.org/docs/2.0/mod/mod_vhost_alias.html#interpol

BUT::

How to take care of the fact that example.com can actually even be example.co.in ??

(For base directory, if I use %2+ on example.co.in, it will give me co.in but I want example.co.in. %1+ on http://abc.example.com, will give me abc.example.com as base directory instead of example.com which I want).

Basically, I want a rule that will work consistentl开发者_运维百科y for: 1) www.abc.example.com

2) abc.example.com 3) www.abc.example.co.in 4) abc.example.co.in

(Note: Apparently, the maximum levels in domain name is 127 http://en.kioskea.net/contents/internet/dns.php3. That means 0.1.2.3.4.example.com is pretty much possible).

cheers,

JP


If you've got just 2 domains you can simply 2 VirtualHosts:

<VirtualHost *:80>
  ServerDomain example.com
  ServerAlias *.example.com
  VirtualDocumentRoot /var/www/%-2%-1/%-3+
</VirtualHost>
<VirtualHost *:80>
  ServerDomain example.co.in
  ServerAlias *.example.co.in
  VirtualDocumentRoot /var/www/%-3%-2%-1/%-4+
</VirtualHost>

You get the idea.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜