Htaccess 重定向异常 [英] Htaccess redirection exception
本文介绍了Htaccess 重定向异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 htaccess 中有此规则以强制 https 导航:
I have this rules in my htaccess in order to force https navigation:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
但我想为页面添加一个例外,让我们将其命名为page.php"
But I want to add an exception for a page let's name it 'page.php'
我该怎么做?谢谢!
推荐答案
只需添加一个否定条件:
Just add a negative condition:
RewriteCond %{REQUEST_URI} !/page\.php$ [NC]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{REQUEST_URI} !/page\.php$
将从该规则中排除 /page.php
.
RewriteCond %{REQUEST_URI} !/page\.php$
will exclude /page.php
from this rule.
还有另一种方法可以使用 RewriteRule
本身中的否定条件:
There is another way of doing so using negative condition in RewriteRule
itself:
RewriteCond %{HTTPS} off
RewriteRule !^page\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC,NE]
这篇关于Htaccess 重定向异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文