Whether you’re running your site on shared infrastructure, a virtual machine or a dedicated server ,installing an SSL certificate enables both HTTP and HTTPS access. Only HTTPS encrypts the data exchanged between the server and your visitors. To ensure full security and SEO compliance, you should enforce HTTPS site-wide using .htaccess.
Before proceeding, make sure:
To test this, open https://yourdomain.com. If you see a secure lock icon in the browser — you’re good to go.
Add the following code to the top of your .htaccess file, located in the root folder of your site (usually /public_html):
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
If the redirect doesn’t work:
After saving the changes:
If you’re using WordPress, forcing HTTPS in .htaccess is not always enough. Update the WordPress Address (URL) and Site Address (URL) under:
Settings → General → change both to https://yourdomain.com.
Also, consider a plugin like Really Simple SSL for automatic handling of mixed content.
Forcing HTTPS with .htaccess is a simple but crucial step to securing your site. It protects data, builds user trust, and supports your SEO efforts. If you’re using shared hosting, VPS, or a dedicated server — the .htaccess method is universal and effective.