Rewrite 302 redirect to 301 redirect after switching to https

Celestial711

Newbie
Joined
Jun 9, 2015
Messages
30
Reaction score
1
I recently moved a site from http to https and then re-directed all my links with https://pastebin.com/rQCnRuBu. It worked and all my links are now redirected to https. I ran an audit with Website Auditor by Link Assistant and it says the site has issues with duplicate http and https and www and non www versions of the site. It appears that my homepage is a 302 re-direct and should be a permanent 301 redirect. Any thoughts on solving matter ?
 
Enter the following code in your .htaccess

Code:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301,NC]

It'll 301 redirect non-www to www version as well as http requests to https.
 
Enter the following code in your .htaccess

Code:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301,NC]

It'll 301 redirect non-www to www version as well as http requests to https.
My website is set to non www not www - is the code still valid?
 
My website is set to non www not www - is the code still valid?


The previous code will redirect non www to www. If you want to redirect http://www.example.com to example.com, use this code instead. Your site will then load at https://example.com

Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301,NC]

You can PM me the url if you want me to test if it's working as it should.
 
If you've working SSL certificate on your website and you'd like force your website to load using 'https' in web-browser then feel free to add the below code in '.htaccess' file under root directory-

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 
Back
Top