Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 390
egdavid Avatar asked Nov 23 '15 15:11

egdavid


People also ask

How do I redirect www to non-www htaccess?

E.g.: RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^www.example.com/$ [NC] RewriteRule ^(. *)$ http://www.example.com [R=301,L] ... @BobbyS I used the solution in this article. It redirects www and HTTP to non-www HTTPS and also handles the trailing / .


1 Answers

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]
like image 134
anubhava Avatar answered Sep 28 '22 15:09

anubhava