Apache .htaccess thường dùng

Cập nhật ngày 04/03/2026
Lượt xem: 12

Thêm header Authorization cho script

RewriteEngine On

RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

Bỏ dấu / ở cuối nếu không phải thư mục

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

Bắt request và chuyền vào php

  • Hiện tại nếu gặp file/thư mục thì không truyền cho php.
  • Phù hợp cho php route
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]