简体   繁体   中英

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:

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:

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:

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} .

You can use this rule:

RewriteEngine On

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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