Htaccess将https重定向到另一个https

时间:2021-01-28 19:40:46

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.

任何帮助将不胜感激。

1 个解决方案

#1


5  

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]

#1


5  

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]