首页 > 解决方案 > 从主页重定向

问题描述

我有一个条件: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

解决方案


请为您的 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]

推荐阅读