[英]How to redirect from HTTPS to HTTP?
我有一個網站。 我需要將所有頁面從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]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.