简体   繁体   English

Htaccess 将 https 重定向到另一个 https

[英]Htaccess redirect https to another https

We have just bought the .com extension for our domain and we are using ssl certificates on both of them:我们刚刚为我们的域购买了 .com 扩展名,并且我们在它们两个上都使用了 ssl 证书:

https://www.domain.net
https://www.domain.com

Now we would like to use the .com extension only and redirect our users from the old domain to the new one using the htaccess file:现在我们只想使用 .com 扩展名,并使用 htaccess 文件将我们的用户从旧域重定向到新域:

http[s]://domain.net -------|
http[s]://www.domain.net ---|---> https://www.domain.com
http[s]://domain.com -------|

I am not very familiar with htaccess so I tried:我对 htaccess 不是很熟悉,所以我试过:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^http[s]?://(www\.)?domain\.com(.*)?$
RewriteRule ^(.*)$ http[s]?://www.domain.com/? [R,L]

That obviously doesn't work!那显然行不通!

Any help would be greatly appreciated.任何帮助将不胜感激。

You cannot match scheme http:// in RewriteCond %{HTTP_HOST} .您不能在RewriteCond %{HTTP_HOST}匹配方案http://

You can use this rule:您可以使用此规则:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [R=302,L]

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM