简体   繁体   English

htaccess将http://(www。)old.com和https://(www。)old.com重定向到https:// new

[英]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.comhttps://old.comhttp://www.old.comhttps://www.old.comhttp://new.comHTTP:// WWW。 new.comhttps: //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.

相关问题 重定向http:// www。 https:// www的旧路径。 新路径(1to1重定向) - Redirect http://www. old path to https://www. new path (1to1 redirect) .htaccess文件没有重定向http:// www。 到https:// www - .htaccess file not redirecting http://www. to https://www htaccess重定向https:// www。 (https://www.example.com)到非www(https://example.com) - htaccess redirect https://www. (https://www.example.com) to non www (https://example.com) htaccess http到带有www的https。 不重定向子域 - htaccess http to https with www. Without redirecting sub domain htaccess强制https和www。 在域上&http在子域上没有www - htaccess force https & www. on domain & http no www on subdomain Getting .htaccess redirects from one domain to another to work for WWW ( both http://www. and https://www.), HTTP and HTTPS - Getting .htaccess redirects from one domain to another to work for WWW ( both http://www. and https://www.), HTTP and HTTPS .htaccess重定向到https和www。 如果启用 - .htaccess redirect to https and www. if enabled htaccess:使用https:// www。 有例外 - Htaccess: Use https://www. with exceptions 将所有非www,www,http://请求重定向到https:// www。 使用.htaccess文件 - Redirect all non-www, www, http:// requests to https://www. using .htaccess file 为什么是http:// www。 转到/index.php和https:// www。 才不是? - Why http://www. goes to /index.php and https://www. does not?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM