[Help] Redirect http to https and www to non-www

Zakhej

Elite Member
Jr. VIP
Joined
Dec 2, 2015
Messages
6,468
Reaction score
2,973
I win some domain in auction. Most of the backlinks are on the homepage and in Http version. So i need to redirect Http to Https. Also some backlinks are on www and non-www. So to backlinks remain i need to change htaccess file with code below! Just want to ask is code correct and is that all i need to do...?


RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
 
My advice: check how the page was built originally and keep everything consistently, don't build on www and non-www based on incoming links
Also just fully redirect from HTTP to https as a general advice

You can go the hard redirect like

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