簡體   English   中英

htaccess 301將https重定向到https,將http重定向到http

[英]htaccess 301 redirect https to https and http to http

我已經看到了許多有關將http重定向到https和將https重定向到http重定向的問題,但是沒有有關將所有流量(http和https都重定向到一個新站點)的問題。

這是我的htaccess文件的樣子,但無法正常工作。 如何將https請求重定向到https://www.mynewsite.com/和將HTTP請求重定向到http://www.mynewsite.com/

RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} ^on
RewriteRule ^(.*)$ https://www.mynewsite.com%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} ^off
RewriteRule ^(.*)$ http://www.mynewsite.com%{REQUEST_URI} [R=301,L]

這應該分別完成將http和https請求重定向到新站點。 HTTP到HTTP和HTTPS到HTTPS,只是從舊的URL到新的URL:

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule ^/?(.*) https://www.mynewsite.com/$1 [R=301,L] 
RewriteCond %{HTTPS} off
RewriteRule ^/?(.*) http://www.mynewsite.com/$1 [R=301,L] 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM