How to Redirect HTTP to HTTPS using .htaccess or web.config

http to https

A brief guide to redirect website from HTTP to HTTPS using .htaccess or web.config file

Website security is an inevitable need for any business, as the user will experience safe environment over the website. Many sites run with both versions HTTP and HTTPS that could cause SSL warnings and entice hackers to breach the website. It is recommended to force SSL connection on your entire website and ensure that web users are browsing your site over HTTPS secure channel.

To redirect website from HTTP to HTTPS, you need to contain following code using .htaccess or web.config files which depends upon server you use.

Redirect HTTP to HTTPS using .htaccess

Linux & cPanel
You need to place below code in .htaccess file in the cPanel on your Linux based server. This code forces users to redirect to HTTPS connection.

RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.domainname.com%{REQUEST_URI} [L,R=301]

Redirect HTTP to HTTPS using web.config

Windows & Plesk
You should use following code using web.config in Plesk panel on your Windows based server to redirect web traffic on HTTPS secure website.

<configuration>
<system.webServer>
<rewrite>
    <rules>
       <rule name="HTTP to HTTPS redirect" stopProcessing="true"> 
         <match url="(.*)" /> 
         <conditions> 
           <add input="{HTTPS}" pattern="off" ignoreCase="true" />
         </conditions> 
         <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
       </rule> 
    </rules>
</rewrite>
</system.webServer>
</configuration>

Where To Buy an SSL Certificate?

If you wish to provide safe browsing experience for your online visitors and looking for cheap SSL certificate, then SSL2BUY can help you to choose right certificate for your website. SSL2BUY offers wide range of SSL certificates at an inexpensive price that matches your business needs. When SSL is enabled on your website, your website will have green padlock and HTTPS just before your website name.

  Best Buy

Comodo PositiveSSL Certificate

AlphaSSL Wildcard Certificate

Comodo UCC/SAN/Multi-Domain SSL

Price (per year)
$8.00
$26.00
$33.00
BUY NOW BUY NOW BUY NOW
Vendor Price
$37.80
$149.00
$155.80
Product SKU S2BCMD301 S2BALPWC102 S2BCMDMD303
Certificate Authority Comodo GlobalSign Comodo
Category Single Domain SSL Wildcard SSL Certificate Multi Domain (SAN) SSL
Validation Method Domain Control Validation Domain Control Validation Domain Control Validation
Domains Secured FQDN (www+non-www) Root Domain and All Sub-Domains Includes 4 domains
Additional Domain Support No No Up to 250 domains
Delivery Time 10 Minutes 10 Minutes 10 Minutes
Supported Key Type(s) RSA, ECC RSA, ECC RSA, ECC
Supported Key Length(s) 2048 bit 2048 bit 2048 bit
Hash Algorithm SHA-2 SHA-2 SHA-2
Server Licenses Unlimited Unlimited Unlimited
Certificate Reissuance Unlimited and Free of Cost Unlimited and Free of Cost Unlimited and Free of Cost
Device Compatibility 100% 100% 100%
Trust Site Seal Comodo Positive SSL Site Seal AlphaSSL Site Seal Comodo Positive SSL Site Seal
CA Warranty $10,000 USD $10,000 USD $10,000 USD
Vendor Refund Policy 30 Days 30 Days 30 Days
Technical Support Free Live Chat and Ticket Support Free Live Chat and Ticket Support Free Live Chat and Ticket Support
Installation Service Purchase on Demand Purchase on Demand Purchase on Demand
Save up to 85% + 10% OFF
About the Author

Meet Solanki

Meet Solanki, an IT maestro with 8+ years of hands-on expertise in the realms of network and server administration. Armed with a Bachelor's degree in Computer Science, Meet takes pride in being more than a tech enthusiast - he ensures that the systems run seamlessly and maintain the highest standards of security. His technical acumen is a testament to his commitment to optimizing system performance and ensuring robust security protocols.

Trusted by Millions

SSL2BUY delivers highly trusted security products from globally reputed top 5 Certificate Authorities. The digital certificates available in our store are trusted by millions – eCommerce, Enterprise, Government, Inc. 500, and more.
PayPal
Verizon
2Checkout
Lenovo
Forbes
Walmart
Dribbble
cPanel
Toyota
Pearson
The Guardian
SpaceX