.htaccess 几个简单应用

IP禁止

Order allow,deny
Deny from 123.45.67.8
Deny from 123.123.7
Allow from all

上面能禁止IP地址在123.45.67.8以及IP地址开头为123.123.7的任何人。例如123.123.74.42 就不能得到访问。

自定义错误页面(直接拷贝即可)

ErrorDocument 404 /error-pages/not-found.html
ErrorDocument 503 /error-pages/service-unavailable.html

禁止访问某个文件

</IfModule>
<Files ~ "./App/Runtime">
order allow,deny
deny from all
</Files>

网址临时更换跳转替换

rewriteCond %{http_host} ^www.share.com [NC]
rewriteRule ^(.*)$ http://www.baidu.com/$1 [R=301,L]

更换默认首页

DirectoryIndex  haha.html

原文地址:https://www.cnblogs.com/zhang-bin/p/10076446.html