使用 mod_rewrite 重定向后如何停止 url 重写?
How can I stop url rewriting after I redirect using mod_rewrite?
使用 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= [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
。
你的规则是这样的:
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= [L,QSA,NC]
使用 THE_REQUEST
而不是 REQUEST_URI
,因为您的最后一条规则是将 .html
请求路由到 cms.php
,从而改变 REQUEST_URI
的值,而 THE_REQUEST
保持不变。
使用 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= [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
。
你的规则是这样的:
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= [L,QSA,NC]
使用 THE_REQUEST
而不是 REQUEST_URI
,因为您的最后一条规则是将 .html
请求路由到 cms.php
,从而改变 REQUEST_URI
的值,而 THE_REQUEST
保持不变。