Bảo mật WP với .htaccess
⭐ Security Headers
Kiểm tra bảo mật tại: https://securityheaders.com/
Nếu như bạn xài wild-card SSL, tức là mọi subdomain của bạn đều hoạt động qua HTTPS thì mới sử dụng dòng này:
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" env=HTTPS
Nếu không đảm bảo được điều đó, hãy cẩn thận, chỉ sử dụng như code bên dưới
#BEGIN Custom Security Headers
# // This will be a security header..
Header always set Strict-Transport-Security "max-age=31536000; preload" env=HTTPS
Header always set Content-Security-Policy "upgrade-insecure-requests"
Header always set X-Content-Type-Options "nosniff"
Header always set X-XSS-Protection "1; mode=block"
Header always set Expect-CT "max-age=7776000, enforce"
Header always set Referrer-Policy: "no-referrer-when-downgrade"
Header always set X-Frame-Options: "SAMEORIGIN"
Header always set Permissions-Policy: ""
#END Custom Security Headers⭐ Bảo mật thư mục wp-includes
Save code bên dưới vào file .htaccess và đặt vào folder wp-includes.
<Files *.php>
Order allow,deny
Deny from all
</Files>
<Files wp-tinymce.php>
Allow from all
</Files>
<Files ms-files.php>
Allow from all
</Files>
Options All -Indexes⭐ Bảo mật thư mục wp-content & mục uploads
<Files *.php>
Order allow,deny
Deny from all
</Files>
Options All -Indexes⭐ Chặn truy cập các file không cho phép
Thêm vào cuối file .htaccess ngang hàng wp-config.php
Code này sẽ giúp chặn việc truy cập vào các file có đuôi: .txt , .sh , .sql,... trong hệ thống WP, và nó loại trừ file robots.txt và ads.txt
Nếu có các đuôi khác cần thêm vào, thì chỉ cần thêm dấu | rồi thêm phần đuôi mở rộng vào.
<FilesMatch "\.(txt|sh|sql|bak|inc|log)$">
Order allow,deny
Deny from all
</FilesMatch>
<Files robots.txt>
Allow from all
</Files>
<Files ads.txt>
Allow from all
</Files>Last updated