如何从HTTPS重定向到HTTP?

时间:2016-05-07 11:59:18

标签: php .htaccess drupal drupal-6

我有一个网站。我需要将所有页面从HTTP重定向到HTTPS。但是有两个页面不应该通过HTTPS提供。

  • 主页 - www.hellomysite.com
  • 经销商页面-www.hellomysite.com/dealers

即使用户输入的网址为https://www.hellomysite.com/dealers,也应通过HTTP提供。 http://www.hellomysite.com/dealers

我用google搜索&找到链接数但没有重定向。

的.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]

如果我再尝试更多,那么我在打开网站时会收到错误

  

此网站有太多重定向

如何重定向主页&经销商页面到HTTP。

2 个答案:

答案 0 :(得分:1)

如果我理解你,以下代码将解决它:

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 

现在您可以强制整个网站从http重定向到https,但www.hellomysite.com和www.hellomysite.com/dealers除外。

注意:请确保在测试上述代码之前清空浏览器缓存

答案 1 :(得分:0)

尝试:

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