[英]Apache: redirect if host doesn't start with www or cdn
My goal is to redirect to domain with www.
我的目标是使用
www.
重定向到域www.
if both these conditions are met: 如果同时满足以下两个条件:
I'm using a .htaccess file with this code, but the second condition is not honoured: 我正在使用带有此代码的.htaccess文件,但不满足第二个条件:
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^cdn\.example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Thank you 谢谢
Using this did the trick: 使用此技巧:
RewriteCond %{HTTP_HOST} !^(cdn|www)\.example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
I already tried it before but was tricked --by a cached redirect-- to think it was not working. 我之前已经尝试过,但是被缓存的重定向欺骗了,以为它不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.