Công nghệ Sói's Tutorials Web

How to redirect HTTP to HTTPS Using .htaccess

Table of Content

How to redirect HTTP to HTTPS Using .htaccess

Redirect All Web Traffic

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

Redirect Only a Specific Domain

RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

Redirect Only a Specific Folder

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} folder
RewriteRule ^(.*)$ https://www.yourdomain.com/folder/$1 [R,L]

Note: Replace “yourdomain” with your actual domain name wherever required. Also, in case of the folder, replace /folder with the actual folder name.

Ví dụ

RewriteEngine On
RewriteCond %{HTTP_HOST} ^api.dothanhlong\.org [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://api.dothanhlong.org/$1 [R,L]

image


Preference

https://www.freecodecamp.org/news/how-to-redirect-http-to-https-using-htaccess/

Leave a Reply

Your email address will not be published. Required fields are marked *