.htaccess子域重定向问题

时间:2010-12-25 14:36:20

标签: .htaccess redirect subdomain

我有一个网站让我们说www.example.com我有一个子域something.example.com

主域和子域都指向目录“public_html”

我在root上有.htaccess,它将没有www的任何URL重定向到www。 对于例如如果用户输入example.com,他将被重定向到www.example.com 如果用户输入example.com/mypage.html,则会将其重定向到www.example.com/mypage.html

现在问题是这也影响了我的子域名。因为如果有人输入something.example.com/visit.html,那么他会重定向到www.example.com/visit.html

我不想要这个!如果用户进入子域,那么我不想重定向到www域。这就是我的.htacces文件中的内容

RewriteCond %{HTTP_HOST} !^www.stackoverflow.com$ [NC]
RewriteRule ^(.*)$ http://www.stackoverflow.com/$1 [R=301,L]

请告诉我,我该怎么办才能解决上述问题?

感谢。

1 个答案:

答案 0 :(得分:0)

您是否可以访问您的网络服务器配置?最好通过配置网络服务器来完成。

在apache上,你可以像这样配置一个虚拟域:

<VirtualHost *:80>

        ServerName somedomainiwanttoredirect.com
        ServerAlias maybe.somemoredomainstoredirect.com
        ServerAlias orsubdomains.toredirect.com
        RewriteEngine On
        RewriteRule ^(.*)$ http://www.target.com/$1 [R=301,L]

</VirtualHost>

在您的真实配置中,www.target.com您添加了您不想重定向的子域: ServerAlias subdomain.target.com