PHP 5.3
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
ErrorDocument 404 https://qkmedica.com
#--------
# Chặn các tham số URL chứa dấu gạch chéo (/) lạ trong giá trị
RewriteCond %{QUERY_STRING} ^.*(=|%3D)[^&\s]*\/[^&\s]* [NC]
RewriteRule ^.*$ - [F,L]
# Chặn các file có đuôi .phtml, .php, .asp, .aspx... trong tham số
RewriteCond %{QUERY_STRING} \.(phtml|php|asp|aspx) [NC]
RewriteRule ^.*$ - [F,L]
# Chặn các query string đáng ngờ
RewriteCond %{QUERY_STRING} (^|&)ID= [NC,OR]
RewriteCond %{QUERY_STRING} (^|&)App= [NC,OR]
RewriteCond %{QUERY_STRING} (^|&)([a-z0-9]+)=.*(win88|bet|casino|alternatif|188|sbotop|fun88|cmd|cmd368|1xbet|22bet|m88) [NC]
# Khi có lỗi 404 hoặc 403 → chuyển về trang chủ
ErrorDocument 404 https://domain.com or https://domain.com.vn
ErrorDocument 403 https://domain.com or https://domain.com.vn
#-----------------#
LARAVEL PHP > 8.2
#-----------------#
3. Bật cache cho trình duyệt
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpeg "access plus 1 year"
...
</IfModule>
4. Ép kiểu file SCSS/SASS/Less thành CSS
<Files ~ "\.(scss|sass|less|postcss)$">
ForceType 'text/css; charset=UTF-8'
</Files>
5. Bật Rewrite URL & bảo vệ thư mục
<IfModule mod_rewrite.c>
RewriteEngine On
# Chặn truy cập trực tiếp vào file PHP trong /public/
RewriteCond %{REQUEST_URI} ^/public/.*\.php$ [NC]
RewriteRule ^ - [F]
# Chặn xem file .git và .env
RedirectMatch 404 /\.git(/|$)
RedirectMatch 404 /\.env(/|$)
7. Giữ nguyên thông tin HTTP Authorization
RewriteCond %{HTTP:Authorization} ^(.+)$
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
Cho phép các request giữ lại token/bearer trong header (thường dùng cho API).
8. Chuyển mọi request về index.php (router Laravel/PHP)
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
Mọi URL không trỏ tới file/thư mục thật sẽ chạy qua index.php → xử lý bằng code PHP (kiểu framework).
9. Chặn truy cập file nhạy cảm
<FilesMatch "phpunit.xml|composer.lock|...">
Require all denied
</FilesMatch>
Chặn các file test, file cấu hình package, file markdown… không cho ai truy cập qua web.
Không có nhận xét nào:
Đăng nhận xét