Loading...
🚀 Chia sẽ code

Cấu hình tự động chuyển http sang https bằng .htaccess

Admin Published on 17 May, 2021

Nếu bạn sử dụng hosting cpanel thì sẽ dễ dàng cài đặt ssl như vậy website bạn sẽ dùng được https.

Nếu trước đây website đang chạy chưa có https bây giờ chuyển sáng thì sẽ dính các link củ google index bạn chỉ cần thì đoạn code tự động redirect link từ http sáng https.

# http to https
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Source mình đang chạy codeigniter, bạn có thể tham khảo full file .htaccess

RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|public|robots\.txt|favicon\.ico)

# http to https
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# www to non-www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

Admin Published on 17 May, 2021

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