我有一个网站。 我需要将所有页面从HTTP重定向到HTTPS的地方。 但是有两个页面不应该通过HTTPS提供。
即使用户输入的网址是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。
如果我了解您,以下代码将解决此问题:
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除外。
注意:在测试上述代码之前,请确保您清空浏览器缓存
尝试:
#Redirect all request to HTTPS
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule !^$|dealer https://hellomysite.com%{REQUEST_URI} [L,R=301]