在使用mod_rewrite
?
我尝试过使用L
和E
标记的不同组合,但尚未找到办法执行此操作。
以下是我最新尝试的.htaccess
文件
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/(basket|order).html [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L,E=STOP:1]
RewriteCond %{ENV:STOP} !1
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/(basket|order).html [NC]
RewriteRule ^ http://www.example.com%{REQUEST_URI} [R=301,L,E=STOP:1]
RewriteCond %{ENV:STOP} !1
RewriteRule ^(.*).html$ cms.php?pagename=$1 [QSA]
RewriteCond %{ENV:STOP} !1
RewriteRule ^$ cms.php [QSA]
例如,每当我尝试打开http://www.example.com/basket.html
时,它都会将我重定向到http://www.example.com/cms.php?pagename=basket
。但这不是正确的,我只是尝试从http
重定向到https
。
答案 0 :(得分:1)
请遵守以下规则:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} /(basket|order)\.html [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} !/(basket|order)\.html [NC]
RewriteRule ^ http://www.example.com%{REQUEST_URI} [R=301,L]
RewriteRule ^$ cms.php [L]
RewriteRule ^(.+?)\.html$ cms.php?pagename=$1 [L,QSA,NC]
使用THE_REQUEST
代替REQUEST_URI
,因为您的最后一条规则是将.html
请求转发给cms.php
,从而更改了REQUEST_URI
的值,而THE_REQUEST
仍然存在不变。