【问题标题】:Redirecting base url only using htaccess仅使用 htaccess 重定向基本 url
【发布时间】:2012-03-14 04:41:49
【问题描述】:

我只想将基本网址重定向到外部网站。

例如,我希望 example.com 重定向到 anotherdomain.com,但我不希望 example.com/path 被重定向。

到目前为止,example.com/path 重定向到 anotherdomain.com/path。 :(

编辑:

首先,感谢您的帮助! example.com 现在重定向到 another.com 而不会影响 example.com 的子路径。

但是,理想情况下,m.example.com 不会重定向到 another.com。所以实际上只是 example.com 重定向到 another.com

【问题讨论】:

    标签: apache .htaccess redirect


    【解决方案1】:

    将此添加到您的.htaccess 中的DocumentRoot。我假设您在服务器上只托管一个域。

    RewriteEngine on
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} !^m\.
    RewriteRule ^$ http://anotherdomain.com [R,L]
    

    【讨论】:

    • 感谢阿努巴瓦!和思考的猴子!我没有设置重写条件
    • 其实没有。因为我有一个移动网站。所以现在,如果我去 m.example.com,它会重定向到 anotherdomain.com(但我不希望它这样做)
    猜你喜欢
    • 2021-10-06
    • 2021-01-30
    • 2015-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-12
    • 1970-01-01
    • 2011-12-23
    相关资源
    最近更新 更多