• Subcribe to Our RSS Feed

[.HTACCESS] RewriteRule For HTTP To HTTPS and HTTPS to HTTP

Oct 23, 2013   //   by admin   //   .htaccess, Open Source, Other, PHP  //  No Comments

Hello Friends,

Today i am sharing with you some .htaccess rules which is very use full in web development. Generally we are using .htaccess for apache rewrite.In this case people directly try domain name into browser.They did not write any protocol like http or https. So browser send request with default protocol http.In this case client fetch security problem.

So i find solution if user doesn’t provide any protocol or none of the both protocol but my rules will be rewrite the request and send with https protocol.

Now i will explain you 2 type of rewrite rules in beneath.

(1) RewriteRule For HTTP To HTTPS

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

(2) RewriteRule For HTTPS To HTTP

RewriteCond %{HTTP} off
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}

Thanks.

Leave a comment

*

Social Media Auto Publish Powered By : XYZScripts.com