redirect域(和所有子域)到其他域

我想redirect:

example.com => example.net whatever.example.com => whatever.example.net 

这是可能做到这一点,而不build立每个单独的子域作为Apache的别名和mod_rewriteredirect? 最好,我只想用DNS做这个,但我不确定这是可能的。

首先,您需要将DNS设置为指向每个域的相同Web服务器。

其次,在你的apache设置中,有多种方法。

1)如果你为每一组子域使用VirtualHosts,你只需添加一个ServerAlias行,就像这样:

 <VirtualHost *:80> ServerName example.com ServerAlias example.net [...] further commands </VirtualHost> <VirtualHOst *:80> ServerName whatever.example.com ServerAlias whatever.example.net [...] further commands </VirtualHost> 

2)如果你不想input每个主机名,你可以使用mod_vhost_alias 。 这是一个configuration示例:

 UseCanonicalName Off VirtualDocumentRoot /path/to/vhosts/-2+ 

这意味着每个域名将连接到由域名减去最后一部分组成的path。 例:

  • www.example.com将使用/path/to/www.example
  • www.example.net将使用/path/to/www.example
  • example.com将使用/path/to/example
  • example.net将使用/path/to/example
  • whatever.example.com将使用/path/to/whatever.example
  • whatever.example.net将使用/path/to/whatever.example

答案是主要是因为DNS只用于使域和它的IP地址之间的关联(看看接受的答案在这里https://stackoverflow.com/questions/9896877/dns-redirect-domain-to-subdomain )。 所以你应该根据这个在你的.htaccess文件中进行修改

 RewriteEngine on Options +FollowSymlinks -MultiViews # handles http redirect sub-dir RewriteCond %{REQUEST_FILENAME} -d RewriteCond %{SERVER_PORT} =80 RewriteCond %{HTTP_HOST} ^(.+\.)?mysite\.com$ [NC] RewriteRule ^/?(.*)$ http://www.anotheriste.com/feed?v=$1 [R=301,L,QSA,NE] # handles http redirect non sub-dir RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{SERVER_PORT} =80 RewriteCond %{HTTP_HOST} ^(.+\.)?mysite\.com$ [NC] RewriteRule ^/?(.*)$ http://www.anotheriste.com/$1 [R=301,L,QSA,NE] # handles https redirect sub-dir RewriteCond %{REQUEST_FILENAME} -d RewriteCond %{SERVER_PORT} =443 RewriteCond %{HTTP_HOST} ^(.+\.)?mysite\.com$ [NC] RewriteRule ^/?(.*)$ https://www.anotheriste.com/feed?v=$1 [R=301,L,QSA,NE] # handles https redirect non sub-dir RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{SERVER_PORT} =443 RewriteCond %{HTTP_HOST} ^(.+\.)?mysite\.com$ [NC] RewriteRule ^/?(.*)$ https://www.anotheriste.com/$1 [R=301,L,QSA,NE] 

更多的意见,你可以在这里find( https://stackoverflow.com/questions/5694503/htaccess-redirect-from-any-subdomain-to-another-domain-and-from-directory-to-que )。