How to redirect http to https in .htaccess
An http to https redirect makes sure visitors and search bots always land on the secure version of the site. You need it right after installing the SSL certificate, otherwise the old http address stays reachable in parallel. On Apache and LiteSpeed the simplest way is a rule in .htaccess.
Check your site
-
Open .htaccess in the site root
In cPanel File Manager go to public_html and turn on Settings > Show Hidden Files. The .htaccess file sits next to index.php; if it is missing, create a new file with that exact name.
-
Make a backup first
Before editing, copy .htaccess to .htaccess.bak. A syntax mistake in this file takes the whole site down with a 500 error, so keep a rollback ready.
-
Add the redirect rule
Right after the RewriteEngine On line add:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
This sends any http request to the same path over https. -
Handle www if needed
If the canonical version is without www, point the www address to the bare domain over https. To avoid a double hop, do it in one rule: add RewriteCond %{HTTP_HOST} ^www\. with the [OR] flag next to the http condition, and set the final https host without www in the RewriteRule.
-
Save and check the syntax
Save the file and open the site straight away. If you get a 500 error, restore .htaccess.bak: the cause is almost always a stray space or a duplicate RewriteEngine On line.
-
Make sure it is a 301, not a 302
A temporary 302 does not pass link weight to search engines. The rule must use R=301, not R=302.
How to verify the result
Open http://your-domain and watch whether the address switches to https automatically. You can inspect the status code and the full redirect chain with the TechGuard redirect checker to confirm it is a real 301 with no extra hops.
Tip: Do not add the redirect while the certificate is not active yet: you will get a loop where the site refuses to open at all.
Related guides
Found problems?
Slow hosting, SSL trouble or frequent downtime? Move to TomisHost: fast hosting with free SSL, daily backups and free migration help.
TomisHost hosting