如何从HTTPS重定向到HTTP?

问题描述 投票:0回答:2

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

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

即使用户输入的网址是https://www.hellomysite.com/dealers ,也应通过HTTP进行投放。 http://www.hellomysite.com/dealers

我用谷歌搜索并找到了许多链接,但没有一个被重定向。

.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。

php .htaccess drupal drupal-6
2个回答
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除外。

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


0
投票

尝试:

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