Wednesday, 4 March 2015

How to redirect https to http in htaccess

Today, htaccess play very important role for SEO, It is used for redirection, rewriting and apache config variable etc.
How to edit your htacess file.
Open your .htaccess file which is mostly in root folder OR in public/public_html folder.
Use following code as per your requirement.(Please have backup your .htaccess file before editing).


https://example.com to http://example.com redirect
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


https://example.com to http://www.example.com redirect
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


http://example.com to https://example.com redirect
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]


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