当用户访问了一个不存在的页面的时候,网页服务器会显示"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>