Nội dung
After the SSL certificate installation is complete, your website will have HTTPS protocol support on the website address of https://
, however, if you access the browser by entering a regular domain name, the website will not automatically redirect over the HTTPS protocol.
So in order for the website to automatically switch over to the HTTPS protocol when accessing it in the usual way, you will need to set up the website to automatically redirect from HTTP to HTTPS.
In this article, AZDIGI will show you to set up an automatic redirection from HTTP to HTTPS in several ways for websites running on Hosting and VPS.
HTTPS redirect using .htaccess file (Hosting or Apache webserver)
Insert the following at the end of the file.htaccess
on your website directory. If you are using Hosting and don’t see the .htaccess
file when you go to File Manager, turn on showing hidden files.
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://tên-miền-của-bạn/\ [R,L]
Remember to change https://tên-miền-của-bạn
to your website’s domain name.
HTTPS redirects on CloudFlare
This method only applies when you are enabling CloudFlare proxy and using an SSL certificate on CloudFlare. Go to your domain management page on CloudFlare, then go to SSL/TLS => Edge Certificates and enable the Always Use HTTPS feature.
HTTPS redirects on the NGINX server
Edit the domain configuration file on NGINX, add the below command and after adding it, reload with the following command
server {
listen 80
server_name example.com www.example.com;
## redirect http to https ##
rewrite ^ https://$server_name$request_uri? permanent;
}
nginx -s reload
If you use Windows Hosting
Add the following code in the web.config file
<rule name="Redirect to HTTP" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{R:1}" pattern="^onepage/(.*)$" negate="true" />
<add input="{HTTPS}" pattern="^ON$" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/{R:0}" redirectType="Permanent" />
</rule>
Wishing you success!