htaccess 强制除一个域之外的 HTTPS 流量

htaccess 强制除一个域之外的 HTTPS 流量

我正在尝试强制除一个域之外的所有流量都使用 HTTPS,但是,我无法使其正常工作。

RewriteEngine On

# Disable directory browsing
Options All -Indexes

# Exclude the following site
#RewriteCond %{HTTP_HOST} !excluded\.example.com [NC]

# For the rest of sites force HTTPS traffic. 
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

结果 > 所有网站都重定向到 HTTPS,包括excluded.example.com这不是我需要的。我想从 HTTPS 中排除该域名

如果有人发现我做错了,我将不胜感激

非常感谢

答案1

RewriteEngine On

# Disable directory browsing
Options All -Indexes

# Exclude the following site
RewriteCond %{HTTP_HOST} !^excluded\.example\.com$ [NC]

# For the rest of sites force HTTPS traffic. 
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

取消注释 RewriteCond 并添加转义字符。^标记字符串的开始和$结束。如果这不起作用,请告诉我!

相关内容