Rayhan Muktader
Rayhan Muktader

Reputation: 2106

HTTPS redirect is not working

This is what I have in my conf file:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^test\.old\.com$ [NC]
RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ https://test-new.com$1 [QSA,R=301,L]

RewriteCond %{HTTP_HOST} ^test\.old\.com$ [NC]
RewriteRule ^(.*)$ http://test-new.com$1 [QSA,R=301,L]

It redirects when I go to test.old.com but no redirection takes place when I try https://test.old.com

How can I redirect https request to new domain with https in the url?

Upvotes: 0

Views: 76

Answers (1)

Panama Jack
Panama Jack

Reputation: 24448

You only need one redirect rule to go to your new domain regardless of http or https is used. If you want to redirect from old to new with https in the new domain, you can use this.

RewriteCond %{HTTP_HOST} ^test\.old\.com$ [NC]
RewriteRule ^(.*)$ https://test-new.com/$1 [QSA,R=301,L]

If you want a one to one rule and redirect http to http and https to https then you can do this.

RewriteCond %{HTTP_HOST} ^test\.old\.com$ [NC]
RewriteCond %{HTTPS} ^on
RewriteRule ^(.*)$ https://test-new.com/$1 [QSA,R=301,L]
RewriteCond %{HTTP_HOST} ^test\.old\.com$ [NC]
RewriteCond %{HTTPS} !^on
RewriteRule ^(.*)$ http://test-new.com/$1 [QSA,R=301,L]

This is providing the fact that you still have a valid certificate for the old domain. If you do not it will not work for https and only from http. You will get a certicate warning and no redirection will not take place until you proceed past that error.

Upvotes: 1

Related Questions