我想将所有流量从HTTP重定向到HTTPS,但前提是特定网址与/ oldsite不同(但仅限于subdomains sub1和sub2)
例如:
http://example.com/any/thing --> redirects to --> https://example.com/any/thing
http://sub1.example.com/any/thing --> redirects to --> https://sub1.example.com/any/thing
但
http://example.com/oldsite/any/thing
和
http://sub1.example.com/oldsite/any/thing -> do not cause this redirect
我试过了:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:(sub1|sub2)\.)?example\.com
RewriteCond %{REQUEST_URI} !^/oldsite [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
谢谢。
更新:还测试了最后两行:
RewriteCond %{THE_REQUEST} !/oldsite [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301, NE]
答案 0 :(得分:0)
确保在HTTPS
关闭时使用您的规则,并使用THE_REQUEST
变量代替REQUEST_URI
:
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !/oldsite [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]