【问题标题】:.htaccess subdomain redirect problem.htaccess 子域重定向问题
【发布时间】:2011-05-30 15:41:20
【问题描述】:

我有一个网站,比如说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]

你能告诉我我应该怎么做才能解决上述问题吗?

谢谢。

【问题讨论】:

    标签: .htaccess redirect subdomain


    【解决方案1】:

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

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

    <VirtualHost *:80>

     服务器名称 somedomainiwanttoredirect.com
            ServerAlias maybe.somemoredomainstoredirect.com
            ServerAlias or subdomains.toredirect.com
            重写引擎开启
            RewriteRule ^(.*)$ http://www.target.com/$1 [R=301,L]

    </VirtualHost>

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

    【讨论】:

    • 我已经这样做了: RewriteCond %{HTTP_HOST} !(.*).stackoverflow.com$ [NC] RewriteRule ^(.*)$ stackoverflow.com/$1 [R=301,L ]
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-28
    • 1970-01-01
    • 2019-10-13
    • 2012-01-01
    • 1970-01-01
    相关资源
    最近更新 更多