Below snippet shows how to redirect a site from non-www to www (or viceversa) and from HTTP to HTTPS. To be more clear, the configuration will redirect the following host names:
1 2 3 |
http://onlinenote.in http://www.onlinenote.in https://onlinenote.in |
to
1 |
https://www.onlinenote.in |
I’ll also show a small change to redirect the www to the non-www version, if you prefer the non-www.
To configure the redirects, add the following redirect rule either to the Apache config file if you have access to it, or to the .htaccess
in the root of your site:
1 2 3 4 5 |
RewriteEngine On RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC] RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301] |
If instead of www.onlinenote.in
you want the default URL to be onlinenote.in
, then simply change the third and the fifth lines:
1 2 3 4 5 |
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] |