This article demonstrates how to redirect users to secure (https://) web site connections, even if they type a non-secure URL (http://) in their web browser. This article applies to servers using Apache or Apache-compatible web servers (such as LiteSpeed).
You may want to ensure that visitors to your web site always use a secure connection. To do this, you can use rewrite rules in a custom .htaccess file.
If you use the rewrite rules in an .htaccess file in the web site's root directory, all requests will be redirected to HTTPS connections. Alternatively, you can modify the rewrite rules in a specific directory's .htaccess file to limit redirection to files in that directory.
Add the following lines to the desired .htaccess file to redirect users from a non-secure URL (http://) to a secure URL (https://).
RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Subscribe to receive weekly cutting edge tips, strategies, and news you need to grow your web business.
No charge. Unsubscribe anytime.
Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.
We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.