1. Home
  2. Redirect to HTTPS Using .htaccess

Redirect to HTTPS Using .htaccess

To use a secure connection between the user and a website you first need to issue and install an SSL certificate in your hosting account.

You can select and purchase an SSL certificate from SuperHosting.BG.

After the SSL certificate has been issued and installed into your hosting account, you can activate a secure connection for your website.

Note: Some types of CMS require that you set up the SSL connection through the website administration.

To enable secure connection you can redirect it by using the .htaccess file, located into the website directory.

Important: If you already have an .htaccess file, containing rules, we recommend making backup before changing anything. You can quickly back up a single file by generating a copy of it.

Redirecting through a secure connection for new websites:

SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "mysite.com"
ErrorDocument 403 https://mysite.com

This type of redirect is suitable for fresh WordPress installations if there aren’t any pages indexed on the web.
Redirect for already existing pages from the website:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://mysupersite.com/$1 [R=301,L]

or:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R=301,L]

This type of redirect will also catch queries with no specified URLs from the website, for example if a user is trying to access a page:

http://mysupersite.com/?p=1

will be redirected to:

https://mysupersite.com/?p=1

Important: After you modify the .htaccess file, carefully scrutinize if everything on the website is properly working. Check if all links, menus, pages and resources are loading correctly via https://.

After modifying the .htaccess file, you might need to clear your browser’s cache in order to view the changes.

See more:

🔗 HTTPS – Part of the Website’s Content is Loaded over an Insecure Connection (HTTP) | Help

Updated on 24.03.2021

Was this article helpful?