[英]htaccess file: Force going to https instead of http except for specific pages
I have read a lot about this, but i still can't figure it out for my case. 我已经阅读了很多关于此的内容,但我仍然无法理解我的情况。 I am trying to force all http requests to go to https except for 2 pages.
我试图强制所有http请求转到https,除了2页。 Those 2 pages requests have parameters passed to them.
这2页请求具有传递给它们的参数。 Here is the code i am using currently:
这是我目前使用的代码:
# Force go to https if user isn't asking for a url that has 'register_user.php' or 'register-customer' inside the url:
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/register_user.php$ [OR]
RewriteCond %{REQUEST_URI} !^/register-customer$ [NC]
RewriteRule ^(.*)$ https://www.myWebsite.com/main-folder/$1 [R,L]
# Force go to http if user is asking for a url that has 'register_user.php' or 'register-customer' inside the url:
RewriteCond %{SERVER_PORT} !80
RewriteCond %{REQUEST_URI} ^/register_user.php$ [OR]
RewriteCond %{REQUEST_URI} !^/register-customer$ [NC]
RewriteRule ^(.*)$ http://www.myWebsite.com/main-folder/$1 [R,L]
This code doesn't do the required job. 此代码不执行所需的工作。 Is there something wrong with it?
它有什么问题吗?
You should use THE_REQUEST
instead of REQUEST_URI
as REQUEST_URI
may change due to other rules. 您应该使用
THE_REQUEST
而不是REQUEST_URI
因为REQUEST_URI
可能会因其他规则而发生变化。
Also you should keep these 2 rules at the top before other rules: 此外,您应该在其他规则之前将这两条规则保持在最顶层:
# Force go to https if user isn't asking for a url that has 'register_user.php' or 'register-customer' inside the url:
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !/(register-customer|register_user\.php)[?/\s] [NC]
RewriteRule ^ https://%{HTTP_HOST}/main-folder%{REQUEST_URI} [R=301,NE,L]
# Force go to http if user is asking for a url that has 'register_user.php' or 'register-customer' inside the url:
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} /(register-customer|register_user\.php)[?/\s] [NC]
RewriteRule ^ http://%{HTTP_HOST}/main-folder%{REQUEST_URI} [R=301,NE,L]
Make sure to clear your browser cache before testing this change. 在测试此更改之前,请务必清除浏览器缓存。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.