【问题标题】:Redirect from main page从主页重定向
【发布时间】:2021-06-18 07:07:13
【问题描述】:

我有一个条件: a) 从 help.example.com 重定向到 example.com/support b) 从其他页面重定向,例如 help.example.com/catalog 到 example.com/catalog

这是我在 .htaccess 文件中所做的一切。 我的代码仅在 example.com/support 上重定向我

RewriteCond %{HTTP_HOST}${REQUEST_URI} ^help\.example\.com/(.+)
RewriteRule ^(.+)$ example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST}${REQUEST_URI} ^help\.example\.com
RewriteRule ^(.*)$ example.com/support/ [R=301,L]

我该如何解决这个问题?

【问题讨论】:

    标签: apache .htaccess


    【解决方案1】:

    请为您的 a - b 条件尝试此规则:

    a) 从 help.example.com 重定向到 example.com/support

    RewriteCond %{HTTP_HOST} ^help\.example\.com$ [NC]
    RewriteRule ^(/?)$ https://example.com/support [R=301,L]
    

    b) 从其他页面重定向,例如 help.example.com/catalog 到 example.com/catalog

    RewriteCond %{HTTP_HOST} ^help\.example\.com$ [NC]
    RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
    

    【讨论】:

    • 当我输入 help.example.com 时,它会将我重定向到 example.com
    • 是的,我做到了!此代码 RewriteCond %{HTTP_HOST} help.denvic.ru [NC] RewriteRule ^$ denvic.ru/support [R=301,L] RewriteCond %{HTTP_HOST} help.denvic.ru [NC] RewriteRule ^(.+)$ @987654322 @ [R=301,L]
    • 感谢您的帮助!
    【解决方案2】:

    使用您显示的示例/尝试,请尝试在您的 htaccess 文件中遵循 htacces 规则。请将这些规则放在文件顶部,同时确保在测试 URL 之前清除浏览器缓存。

    这将捕获help.example.comwww.help.example.com 这两种网址。

    RewriteEngine ON
    RewriteCond %{HTTP_HOST} ^(?:www\.)?help\.example\.com$ [NC]
    RewriteRule ^/?$ https://example.com/support [NE,R=301,L]
    

    【讨论】:

    • 我需要将 help.example.com 重定向到 example.com/support。但其他 url 由掩码 help.example.com/* -> example.com/* 重定向
    • @KirillRyzhkov,好的,现在请尝试我编辑的规则,这些规则将从https://help.example.com 重定向到https://example.com/support,让我知道进展如何?
    • @KirillRyzhkov,请确保在测试 URL 之前清除浏览器缓存。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-14
    • 2013-08-20
    • 1970-01-01
    • 2012-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多