Redirect from http to https using htaccess

Some case you want that only some of the pages to redirect to https but not all pages.

In that case the code in above post will not work hence it will redirect all pages to https.

To redirect only some of the pages you need to use below code in your htaccess file.
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} order.php [OR]
RewriteCond %{REQUEST_URI} payment.php [OR]
RewriteCond %{REQUEST_URI} success.php
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

From above code in your website only order.php, payment.php and success.php will be redirect to https protocol.

Here I have used RewriteCond with OR condition. If we use OR condition than Rule will be apply if any of the condition gets true. For more detail about OR condition Check here.

Written by 

I am Sakthivel Madesh, a certified Salesforce Advanced Developer & Administrator working on Salesforce Technology since 2011. I am currently working in Techforce Services as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 14x Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead 5x Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.

Leave a Reply