简体   繁体   English

基于域的无提示重定向

[英]Silent redirect based on domain

I've set up my own server. 我已经设置了自己的服务器。

Let's say my main server folder is /home/www and I've set the nameservers so that all domains point to this location. 假设我的主服务器文件夹为/home/www并且设置了名称服务器,以便所有域都指向该位置。

Now, here's what I want to do : 现在,这是我想做的:

  • Have each domain's files in a separate subfolder 将每个域的文件放在单独的子文件夹中
  • Based on the domain requested, silently redirect to the appropriate subfolder 根据请求的域,以静默方式重定向到相应的子文件夹

Eg 例如

  • if we need somedomain.com or www.somedomain.com or www.somedomain.com/anything/ (or any such variation for that matter) redirect the request from /home/www/ to /home/www/somedomain.com/ 如果我们需要somedomain.comwww.somedomain.comwww.somedomain.com/anything/ (或与此有关的任何此类变体),将请求从/home/www/重定向到/home/www/somedomain.com/

How can this be done? 如何才能做到这一点?


And here's what I've tried (but given that .htaccess is definitely ... not my thing, it'll most likely be close to non-sensical...) : 这就是我尝试过的方法(但鉴于.htaccess绝对是…… 不是我的事,它很可能接近无意义的……):

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www.)?somedomain.com$ [NC]
RewriteRule ^(/)?$ somedomain.com [L]

There are two possible choices. 有两种可能的选择。 you can create Virtual Host for each domain and set virtual document root. 您可以为每个域创建虚拟主机并设置虚拟文档根目录。 Or You can use rewrite rule. 或者您可以使用重写规则。

From apache Virtual host documentation: 从apache虚拟主机文档中:

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /www/www.example1.com
ServerName www.example1.com

# Other directives here

</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/www.example2.org
ServerName www.example2.org

# Other directives here

</VirtualHost> 

You can find out more in http://httpd.apache.org/docs/2.2/vhosts/examples.html 您可以在http://httpd.apache.org/docs/2.2/vhosts/examples.html中找到更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM