简体   繁体   English

通过 .htaceess 将 http://example.com 重定向到 https://www.dummy.com/

[英]Redirecting http://example.com to https://www.dummy.com/ via .htaceess

A client of mine wants to change their domain name, but wants to keep their Google ranking.我的一个客户想要更改他们的域名,但想要保持他们的 Google 排名。 To do this, they've pointed two domain names to the same IP, but we're having an issue where if you visit the site via the old domain, you get a security certificate warning and the page just loads with the old domain name.为此,他们将两个域名指向同一个 IP,但我们遇到了一个问题,如果您通过旧域访问该站点,您会收到安全证书警告,并且该页面仅使用旧域名加载.

What I'd like to do is detect when someone's coming to the site via the old domain and rewrite it to the new domain.我想做的是检测何时有人通过旧域访问该站点并将其重写为新域。 For example, if they where to visit example.com/some-page.htm , it would rewrite to https://www.dummy.com/some-page.htm .例如,如果他们访问example.com/some-page.htm ,它将重写为https://www.dummy.com/some-page.htm

I found this code snippet somewhere that purports to do this, but it just brings the site down:我在某处发现了此代码片段,声称可以执行此操作,但它只会使网站瘫痪:

RewriteCond %{HTTP_HOST} !^example.com$ [NC]
RewriteRule ^(.*)$ https://www.dummy.com/$1 [R=301,L]

This is a WordPress site, so I'm using the normal WordPress rewrite rules, and I'm using the HTML5 Boiler Plate .htacess to enable http > https redriects, non-www > www redirects, and force HTTP Strict Transport Security, if any of that makes a difference.这是一个 WordPress 站点,所以我使用普通的 WordPress 重写规则,并且我使用HTML5 Boiler Plate .htacess启用 http > https 重定向、非 www > www 重定向,并强制 HTTP 严格传输安全,如果任何一个都会有所作为。

You need to change condition to:您需要将条件更改为:

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^ https://www.dummy.com%{REQUEST_URI} [NE,R=301,L]

However keep in mind if you visit https://exampl.com and certificate is for dummy.com then SSL cert warning will still be there because SSL handshakes before mod_rewrite is invoked for redirecting to new site .但是请记住,如果您访问https://exampl.com并且证书用于dummy.com那么 SSL 证书警告仍然存在,因为在调用mod_rewrite之前会进行SSL 握手以重定向到新站点

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 htaccess将http://example.com重写为http://www.example.com,但将https://www.example.com重写为https://example.com - htaccess rewrite http://example.com to http://www.example.com but https://www.example.com to https://example.com http://example.com、http://www.example.com和https://example.com到https://www.example.com - http://example.com, http://www.example.com and https://example.com to https://www.example.com 解析 http://www.example.com 以通过 htaccess 永久重定向到 https://example.com - Resolving http://www.example.com to permanently redirect to https://example.com via htaccess 通过htaccess将所有http和https:// www重定向到https://example.com - Redirect all http and https://www to https://example.com via htaccess 在htacess中从https://example.com重定向到https://www.example.com - Redirecting from https://example.com to https://www.example.com in htacess 将https // example.com重定向到https://www.example.com -opencart v 2.2.0.0 - Redirecting https//example.com to https://www.example.com -opencart v 2.2.0.0 Avoid multiple page redirects http://example.com > https://example.com -> https://www.example.com - Avoid multiple page redirects http://example.com > https://example.com -> https://www.example.com 将 http 和 www 都重定向到 https://example.com - Redirect BOTH http and www to https://example.com 将https://example.com重定向到https://www.example.com - Redirect https://example.com to https://www.example.com 将https://www.example.com重定向到https://example.com - Redirect https://www.example.com to https://example.com
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM