Htaccess redirection exception

痞子三分冷 提交于 2019-12-13 04:35:39

问题


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]

But I want to add an exception for a page let's name it 'page.php'

How can I do this? Thanks!


回答1:


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$ will exclude /page.php from this rule.

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]


来源:https://stackoverflow.com/questions/52037601/htaccess-redirection-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!