Home Hosting Knowledge Set HTTP to HTTPS auto-redirect

Set HTTP to HTTPS auto-redirect

by Thạch Phạm
Published: Last Updated on
A+A-
Reset

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/$1 [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.

screenshot 2022 12 15 11.51.22@2x

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!

Đánh giá

Tham gia nhóm hỗ trợ Server - Hosting

Tham gia nhóm Hỗ trợ Server - Hosting & WordPress để cùng nhau hỏi đáp và hỗ trợ các vấn đề về WordPress, tối ưu máy chủ/server.

Tham gia ngay

Bài viết cùng chuyên mục

AZDIGI – Không chỉ là đơn vị hàng đầu trong lĩnh vực Web Hosting và Máy chủ, chúng tôi mong muốn mang lại những kiến thức bổ ích nhất và luôn cập nhật thường xuyên cho cộng đồng người đam mê thiết kế website, công nghệ,…

Vui lòng không sao chép nội dung nếu chưa xin phép. Designed and Developed by PenciDesign