當(dāng)用戶訪問了一個(gè)不存在的頁面的時(shí)候,網(wǎng)頁服務(wù)器會顯示"404 file not found"錯(cuò)誤。有很多CMS可以讓你設(shè)置自定義的錯(cuò)誤頁面,但最簡單的方法是更改htaccess:
ErrorDocument 404 /404.html
5、設(shè)置目錄的默認(rèn)頁面
假如你需要為不同的目錄設(shè)置不同的默認(rèn)頁面,你可以很容易的通過 .htaccess 實(shí)現(xiàn):
DirectoryIndex about.html
6、基于referer來限制網(wǎng)站訪問
站長通常不會限制網(wǎng)站訪問,但是當(dāng)你發(fā)現(xiàn)有一些網(wǎng)站盡給你帶來垃圾流量的話,你就應(yīng)該屏蔽他們:
<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上傳文件大小
這招在共享空間的服務(wù)器上很有用,可以讓我的用戶上傳更大的文件。第一個(gè)是設(shè)置最大的上傳文件大小,第二個(gè)是設(shè)置最大的POST請求大小,第三個(gè)PHP腳本最長的執(zhí)行時(shí)間,最后一個(gè)是腳本解析上傳文件的最長時(shí)間
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、壓縮文件
你可以通過壓縮文件來減少網(wǎng)絡(luò)流量,也頁面裝載時(shí)間:
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、緩存文件
這一點(diǎn)還需要解釋嗎?
<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>