[英]htaccess redirecting http://(www.)old.com and https://(www.)old.com to https://new
I am migrating a site over to a new domain, and whilst doing moving the entire site over onto https. 我正在将网站迁移到新域,同时将整个网站迁移到https上。 I need the following scenarios to all redirect to https://new.com 我需要以下方案全部重定向到https://new.com
http://old.com , https://old.com , http://www.old.com , https://www.old.com , http://new.com , http://www.new.com , https://www.new.com http://old.com , https://old.com , http://www.old.com , https://www.old.com , http://new.com , HTTP:// WWW。 new.com , https: //www.new.com
I have been trying to work this out all afternoon and can get some scenarios working, but other not all. 我一直在努力解决整个下午的问题,可以使某些方案工作,但还不能解决所有问题。 My code at the moment looks like this.... 目前,我的代码如下:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.old\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.new\.com$
RewriteRule (.*)$ https://new.com/$1 [R=301,L]
It doesn't work for https://(www.)old.com . 它不适用于https://(www。)old.com 。 and http://(www.)old.com gets redirected to http://new.com . 并且http://(www。)old.com重定向到http://new.com 。
Any help would be gratefully received. 任何帮助将不胜感激。 Thanks. 谢谢。
Don't use a multitude of checks if the request was made against any of the “wrong” domains, check it for whether it was not made against the single right one. 不要对请求是否针对任何“错误”域进行大量检查,请检查是否不是针对单个正确域提出的。
# if request was not made against new.com,
RewriteCond %{HTTP_HOST} !^new\.com$ [OR]
# or if the request was not made via HTTPS
RewriteCond %{HTTPS} off
# redirect to https://new.com/…
RewriteRule (.*) https://new.com/$1 [R=301,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.