htaccess重定向避免使用特定域

时间:2016-03-29 18:02:11

标签: .htaccess redirect ssl

RewriteCond %{HTTP_HOST} !^(www\.)?(domaintoavoid1|domaintoavoid)\.com$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} !^(www\.)?(domaintoavoid1|domaintoavoid2)\.com$ [NC]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https%1://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

我目前有这个www / https重定向,但我有一些域名,我没有设置SSL证书,我希望能够完全绕过重定向。目前还没有工作,domaintoavoid.com和www.domaintoavoid.com仍然被重定向到https。

1 个答案:

答案 0 :(得分:0)

在单独的规则中这样做

# skip these domains from https/www rule
RewriteCond %{HTTP_HOST} ^(?:www\.)?(?:domaintoavoid1|domaintoavoid)\.com$ [NC]
RewriteRule ^ - [L]

RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,R=301,NE]

确保在测试之前清理浏览器缓存。