简体   繁体   English

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

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

I've seen lots of questions about http to https and https to http redirects, but nothing about redirecting all traffic, both http and https to a new site. 我已经看到了许多有关将http重定向到https和将https重定向到http重定向的问题,但是没有有关将所有流量(http和https都重定向到一个新站点)的问题。

Here's what my htaccess file looks like, but it is not working. 这是我的htaccess文件的样子,但无法正常工作。 How can I redirect https requests to https://www.mynewsite.com/ and http requests to http://www.mynewsite.com/ ? 如何将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]

This should accomplish redirecting http and https requests to the new site respectively. 这应该分别完成将http和https请求重定向到新站点。 HTTP to HTTP and HTTPS to HTTPS, just from the old URL to the new one: 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