Skip to main content

Posts

Showing posts from July, 2016

How To Redirect Non-WWW to WWW, HTTPS & Vice Versa Using Htaccess

I always see that most of the web developers are stuck with URL redirection. Like redirect Non-WWW to WWW, Non-WWW to HTTPS and WWW to Non-WWW, WWW to HTTPS using .htaccess file. So, here I listed all the code of URL redirection using htaccess. Hope it helps you. Non-WWW and WWW to https://www.example.com/ RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301] RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301] Non-WWW and WWW to https://example.com/ RewriteEngine On RewriteCond %{HTTPS} off  RewriteCond %{ENV:HTTPS} off  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]  RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]  RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301,NE] Non-WWW and /index.php  to WWW Redirect RewriteEngine on RewriteCond %{HTTP_HOST} !^www\.example\.com RewriteRule (.*) http://www.example.com/$1 [R=301,L] RewriteRule ^(.