.htaccess htaccess重写-重定向到另一个子域正在循环
我正在尝试将两种URL重定向到一个子域,将所有其他URL重定向到我的主域。 一个具体的例子:.htaccess htaccess重写-重定向到另一个子域正在循环,.htaccess,subdomain,rewriting,.htaccess,Subdomain,Rewriting,我正在尝试将两种URL重定向到一个子域,将所有其他URL重定向到我的主域。 一个具体的例子: 以/my account/*开头的“我的帐户”页面和订阅页面必须重定向到。必须保留uri 所有其他内容,如/新闻或主页,必须仅在www.domain.com上查看 以下是我迄今为止所尝试的: # All urls except my-account/* and subscription are redirected to the main domain RewriteCond %{HTTP_HOST
- 以/my account/*开头的“我的帐户”页面和订阅页面必须重定向到。必须保留uri
- 所有其他内容,如/新闻或主页,必须仅在www.domain.com上查看
# All urls except my-account/* and subscription are redirected to the main domain
RewriteCond %{HTTP_HOST} ^my-account\.domain\.(.+)$
RewriteCond %{REQUEST_URI} !^my-account/
RewriteCond %{REQUEST_URI} !^subscription$
RewriteRule ^(.*)$ http://www.domain.%1/$1 [L,QSA,R=301]
# subscription page is redirected to my-account subdomain
RewriteCond %{HTTP_HOST} ^www\.domain\.(.+)$
RewriteRule ^subscription$ https://my-account.domain.%1/subscription[L,QSA,R=301]
# All my-account/* pages are redirected to my-account subdomain
RewriteCond %{HTTP_HOST} ^www\.domain\.(.+)$
RewriteRule ^my-account/(.*)$ https://my-account.domain.%1/my-account/$1 [L,QSA,R=301]
每一条规则都是独立工作的,但如果我一起尝试所有规则,我就会陷入一个无限循环
有人知道如何预防吗?规则看起来不错,但第二条规则中缺少了一个空格:
RewriteRule ^subscription$ https://my-account.domain.%1/subscription[L,QSA,R=301]
# -----------------------------------------------------------------^
但您可能可以将它们组合成一条规则:
RewriteCond %{HTTP_HOST} ^www\.domain\.(.+)$
RewriteRule ^(subscription|my-account/.*)$ https://my-account.domain.%1/$1 [L,QSA,R=301]
另外,请确保在测试时清除缓存,因为301重定向是永久性的,浏览器将缓存它们。谢谢您的回答!
打字错误来自我的复制/粘贴和组合,但不会改变任何其他规则的问题。我留着以后用;)
我试过这样一个相反的规则:
#RewriteCond %{HTTP_HOST} !^my-account\.domain\.(.+)$ [NC]
#RewriteCond %{REQUEST_URI} ^/subscription$ [OR]
#RewriteCond %{REQUEST_URI} ^/my-account/ [NC]
#RewriteRule ^(.*)$ https://my-account.domain.%1/$1 [L,R=301]
它也可以工作,但不能与另一个结合使用。它不再循环,但如果我尝试http/www.domain.com/subscription之类的内容,我会被重定向到www.domain.com,url会被截断。似乎无法正确识别重写条件,但仍然无法找到原因