我有一个网站。我需要将所有页面从HTTP重定向到HTTPS。但是有两个页面不应该通过HTTPS提供服务。
- 主页-www.hellomysite.com
- 经销商页面-www.hellomysite.com/Dealers
即使用户已将url输入为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.hellommysite.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]