sr1
sr1

Reputation: 251

Redirect an Old Domain to a New Domain with HTTPS in .htaccess

Let's say we have,

Old Domain : http://www.olddomain.com
New Domain : https://www.newdomain.org

Here's my .htaccess file data :

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^olddomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$
RewriteRule ^/?$ "https\:\/\/www\.newdomain\.org\/" [R=301,L]

Sometimes while redirection, browsers are displaying the Security error such that it is untrusted.

Now,

  1. How to make this successfull ?
  2. How to redirect this from non-www to www ?

Upvotes: 4

Views: 4006

Answers (1)

anubhava
anubhava

Reputation: 786091

Change the order of your rules and clear your browser cache before you test it:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^ https://www.newdomain.org%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.newdomain.org%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Upvotes: 3

Related Questions