當用戶訪問了一個不存在的頁面的時候,網頁服務器會顯示"404 file not found"錯誤。有很多CMS可以讓你設置自定義的錯誤頁面,但最簡單的方法是更改htaccess:
ErrorDocument 404 /404.html
5、設置目錄的默認頁面
假如你需要為不同的目錄設置不同的默認頁面,你可以很容易的通過 .htaccess 實現:
DirectoryIndex about.html
6、基于referer來限制網站訪問
站長通常不會限制網站訪問,但是當你發現有一些網站盡給你帶來垃圾流量的話,你就應該屏蔽他們:
<IfModule mod_rewrite.c>
RewriteEngine on RewriteCond %{HTTP_REFERER} spamteam.com [NC,OR]
RewriteCond %{HTTP_REFERER} trollteam.com [NC,OR]
RewriteRule .* – [F]
</ifModule>
7、限制PHP上傳文件大小
這招在共享空間的服務器上很有用,可以讓我的用戶上傳更大的文件。第一個是設置最大的上傳文件大小,第二個是設置最大的POST請求大小,第三個PHP腳本最長的執行時間,最后一個是腳本解析上傳文件的最長時間
php_value upload_max_filesize 20M
php_value post_max_size 20M
php_value max_execution_time 200
php_value max_input_time 200
8、壓縮文件
你可以通過壓縮文件來減少網絡流量,也頁面裝載時間:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
9、緩存文件
這一點還需要解釋嗎?
<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf|js|css|pdf)$">
HeadersetCache-Control "max-age=2592000″
</FilesMatch>
10、添加尾部的反斜杠
我并不確定,但是很多文章,很多人都說添加尾部反斜杠有益于SEO:
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
</IfModule>