How to redirect from HTTPS to HTTP?

ε祈祈猫儿з 提交于 2019-12-25 04:56:29

问题


I have a Website. Where I need to redirect all the pages from HTTP to HTTPS. But there are two page which should not served over HTTPS.

  • Home Page - www.hellomysite.com
  • Dealers Page -www.hellomysite.com/dealers

Even if user has entered the url as https://www.hellomysite.com/dealers, it should be served over HTTP. http://www.hellomysite.com/dealers

I googled & found number of links but none of them is redirected.

.htaccess

  #Redirect all request to HTTPS
  RewriteCond %{HTTPS} off [OR]
  RewriteCond %{HTTP_HOST} ^www.hellomysite\.com*
  RewriteRule ^(.*)$ https://hellomysite.com/$1 [L,R=301]


  #RewriteCond %{HTTPS}  on [OR]
  #RewriteRule  ^https://hellomysite.com/dealers$   http://hellomysite/dealers [R=301,L,QSA]

If I try anything more, then I get an error on opening the site as

This website has too many redirects

How do I redirect Home Page & the dealers page to HTTP.


回答1:


If i understand you the following code will solve it :

RewriteEngine On
RewriteCond %{HTTPS} =off

RewriteCond %{SCRIPT_FILENAME} !\/index\.php [NC]
#the above line will exclude https://www.hellomysite.com/index.php
# from the following rules

RewriteCond %{SCRIPT_FILENAME} !\/dealers\.php [NC]
# the above line will exclude the https://www.hellomysite.com/dealers.php
# from the following rules

RewriteRule (.+) https://%{HTTP_HOST}/$1 [L,R=301]
# above line will force every pages and directories ,except those who 
# excluded above and the main root , to redirect from http to https
# (.+) means not to consider http://www.hellomysite.com/ and if you
# change it by  (.*) it will be considered 

Now you can force entire web site to redirect from http to https except www.hellomysite.com and www.hellomysite.com/dealers.

Note : please make sure that you empty browser cache before testing above code




回答2:


Try :

  #Redirect all request to HTTPS
  RewriteCond %{HTTPS} off [OR]
  RewriteCond %{HTTP_HOST} ^www\.
  RewriteRule !^$|dealer https://hellomysite.com%{REQUEST_URI} [L,R=301]


来源:https://stackoverflow.com/questions/37088256/how-to-redirect-from-https-to-http

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