.htaccess詳細設置指南(未開啟.htaccess請先開啟.htaccess功能):
設置網站錯誤頁面
ErrorDocument 400 /error_pages/400.html
ErrorDocument 401 /error_pages/401.html
ErrorDocument 403 /error_pages/403.html
ErrorDocument 404 /error_pages/404.html
ErrorDocument 500 /error_pages/500.html
設置網頁301重定向
#從 old_dir 目錄重定向到 new_dir 目錄
Redirect /old_dir/ //www.yourdomain.com/new_dir/index.html
#把通過二級目錄訪問的請求301重定向到二級域名
RedirectMatch 301 /dir/(.*) //dir.yourdomain.com/$1
禁止指定IP段用戶的訪問
#禁止 IP 為 255.0.0.0 和 123.45.6.區段的 IP 訪問
order allow,deny
deny from 255.0.0.0
deny from 123.45.6.
allow from all
禁止指定來源網頁訪問
#禁止從 otherdomain.com 和 anotherdomain.com 的來源訪問
RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} otherdomain\.com [NC,OR]
RewriteCond %{HTTP_REFERER} anotherdomain\.com
RewriteRule .* – [F]
圖片防盜鏈設置
#從本站以外的域名訪問圖片,一律顯示 feed.jpg
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^//(www\.)?yourdomain.com/.*$ [NC]
RewriteRule \.(gif|jpg|png)$ //www.yourdomain.com/feed.jpg [R,L]
設置文件夾首頁
#防止顯示文件夾列表,當訪問文件夾時,服務器會查找index.html,并將其做為首頁文件,如不存在依次向后查找
DirectoryIndex index.html index.cgi index.php
設置多媒體文件為可下載而非播放
AddType application/octet-stream .mp3 .mp4
自定義HTTP報頭
Header set X-Pingback “//www.yourdomain.com/xmlrpc.php”
Header set article-by “yourdomain.com”
設置文件過期時間 Cache Control
# 啟用有效期控制
ExpiresActive On
# gif/png/jpg 有效期為1個月
ExpiresByType image/gif “access plus 1 month”
ExpiresByType image/png “access plus 1 month”
ExpiresByType image/jpg “access plus 1 month”
# js/css 有效期為1星期
ExpiresByType text/javascript “access plus 1 week”
ExpiresByType text/css “access plus 1 week”


發表評論 取消回復