Tạo tệp .htaccess
Tạo quy tắc Apache .htaccess cho chuyển hướng, rewrite và bảo mật
Quy tắc Apache
Kết hợp chuyển hướng, lưu đệm và định tuyến SPA trong tệp .htaccess có thể tải xuống.
Cần Apache 2.4, các module tương ứng và quyền AllowOverride. Hãy thử trên môi trường staging. Nếu proxy xử lý TLS, cần thiết lập nhận diện HTTPS tin cậy trên máy chủ trước.
Chuyển hướng dùng tên miền cố định ở trên. Khi tắt Bắt buộc HTTPS, giao thức HTTP hoặc HTTPS hiện tại được giữ nguyên. Trình duyệt có thể lưu chuyển hướng vĩnh viễn.
.htaccess
# Generated by KitLocal — Apache 2.4; AllowOverride must permit these directives.
RewriteEngine On
# Canonical redirect (fixed host avoids trusting HTTP_HOST).
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L,NE]
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/css application/json application/javascript image/svg+xml
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
</IfModule>
<IfModule mod_headers.c>
Header always set X-Content-Type-Options "nosniff"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>
26 dòng893 byte.htaccess