开发者

Force subset of webpages as HTTPS

开发者 https://www.devze.com 2023-03-19 06:30 出处:网络
I would like to force a subset of webpages to https and all other webpages as http. In htaccess I use the following script that I found in another post, but that wasn\'t working...

I would like to force a subset of webpages to https and all other webpages as http. In htaccess I use the following script that I found in another post, but that wasn't working...

RewriteCond %{HTTPS} off
RewriteRule ^(login|signup)\.php https://%{HTTP_HOST}%{REQUEST_URI} [R,L,QSA]

RewriteCond %{HTTPS} on
RewriteCond ${REQUEST_URI} !(login|signup)\.php
RewriteRule (.*) http://%{HTTP_HOST}%开发者_如何学Go{REQUEST_URI} [R,L,QSA]

HTTP is forced as it should be, HTTPS is forced as it should be, but eg https://mywebsite.com/signup produces an infinite loop error in my browser. Any ideas what goes wrong?

I changed to code to the following which seems to work, but now the SSL is only partially implemented due to secure and insecure items on the webpage. I checked the URLS to e.g. images, style sheets and external javascript files bit these are all relative and shouldn't pose a problem... If someone knows how to deal with this I'd be glad to hear it.

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/login$ [OR]
RewriteCond %{REQUEST_URI} ^/signup$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !login$
RewriteCond %{REQUEST_URI} !signup$
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}  [R,L]


  1. Try adding this line somewhere on top of your .htaccess:

    Options +FollowSymLinks -MultiViews

  2. Maybe you have some other rules that do this redirect -- it would be good if you provide whole contents of your .htaccess file.

  3. You may have redirect inside the actual php script.

In any acse -- if you can edit Apache's config files (httpd.conf or httpd-vhost.conf) then you can enable rewrite debugging (RewriteLoglevel 9) and see what exactly is going on -- this is the best option (if you can).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号