Sử dụng htaccess để tối ưu và bảo mật website
- Thứ tư - 24/07/2013 22:47
- |In ra
- |Đóng cửa sổ này
1. Bảo vệ tệp tin
2. Tắt chữ ký số của web server
3. Giới hạn upload
5. Giới hạn quyền truy cập
6. Trang lỗi tùy chỉnh
7. Tắt liệt kê nội dung thư mục
8. Chuyển hướng 301
9. Chống ăn cắp băng thông như hình ảnh, video (bandwidth)
10. Bật nén PHP compression (bandwidth)
11. Thiết lập canonical url cho website
1.BƯỚC 1, TẠO FILE .HTACCESS.Mở Notepad hoặc phần mềm text editor. Lưu và Đặt tên file htaccess.txt.
2. NHẬP NỘI DUNG VÀO FILE HTACCESS.TXT.
# Bảo vệ file file htaccess
#Tắt chữ ký số của web server
order allow,deny
deny from all
# Bảo vệ file cấu hình config.php# disable the server signature
ServerSignature Off
# limit file uploads to 10mb
LimitRequestBody 10240000
# Giới hạn truy cập, chặn IP
order allow,deny
deny from all
# Tạo Trang lỗi tùy chỉnhorder allow,deny
#deny from 000.000.000.000
allow from all
# Tắt liệt kê nội dung thư mục# custom error docs
ErrorDocument 404 /notfound.php
ErrorDocument 403 /forbidden.php
ErrorDocument 500 /error.php
# Chuyển hướng 301Options All -Indexes
# Khóa tên miền tham chiếuRedirect 301 /old.php http://www.yourdomain.com/new.php
Chống ăn cắp băng thôngRewriteEngine on
RewriteCond %{HTTP_REFERER} digg\.com [NC]
RewriteRule .* – [F]
Nén file#disable hotlinking of images with forbidden or custom image option
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com/.*$ [NC]
#RewriteRule \.(gif|jpg)$ – [F]
#RewriteRule \.(gif|jpg)$ - [R,L]
Tránh trùng lặp nội dung# php compression – use with caution
php_value zlib.output_compression 16386
# Chống spam comments# set the canonical url
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]
RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .comments-post\.php*
RewriteCond %{HTTP_REFERER} !.*yourdomain.com.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]
3. UPLOAD HTACCESS.TXT LÊN SERVER.Sử dụng ftp client (sử dụng ASCII mode) và đổi tên file là .htaccess.
CHMOD file .htaccess sang 644.
4. Kiểm tra kết quả.