.htaccess重写强制HTTPS,如何避免某些域名?
我想强制我的一个网站使用HTTPS。不幸的是,我的服务器上有其他网站,我不想将它们重定向到https。我试图添加重写条件,但不起作用。你知道为什么吗?我的目标是避免botletter.com的https重定向.htaccess重写强制HTTPS,如何避免某些域名?,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我想强制我的一个网站使用HTTPS。不幸的是,我的服务器上有其他网站,我不想将它们重定向到https。我试图添加重写条件,但不起作用。你知道为什么吗?我的目标是避免botletter.com的https重定向 RewriteEngine on RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTP_HOST} !http://botletter.com [NC] RewriteRule ^ https://www.%{HTTP_HOST}
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !http://botletter.com [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP_HOST} !http://www.botletter.com [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
谢谢。您可以使用:
RewriteEngine on
# To https www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !(botletter\.com|eedart\.co|other\.com) [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
# To https
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !(botletter\.com|eedart\.co|other\.com) [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
# botletter to www.botletter
RewriteCond %{HTTP_HOST} ^(botletter\.com|eedart\.co|other\.com) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
根据您的配置,您可能需要使用:
重写cond%{HTTP:X-Forwarded-Proto}!https而不是RewriteCond%{https}offhtaccess将该规则集放置在http服务器主机配置中,而不是使用动态配置文件。当时的情况甚至更快。您可以创建一个单独的文件来保存这些规则,并将其包含在所有需要的虚拟主机定义中。谢谢,它可以正常工作!我如何添加其他域名以避免?我可以添加一行像RewriteCond%{HTTP_HOST}这样的代码吗!重写cond%{HTTP_HOST}后的feedart.co[NC]!botletter.com[NC]它似乎不起作用