在这篇文章中,老蒋整理几个比较使用的且在Apache引擎中的.htaccess文件中设置的技巧,可以控制网站伪静态、防盗链、安全等。这里老蒋示范的是用wordpress网站程序实现的。
1、重定向日期格式为Postname格式
RedirectMatch 301 /([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ http://www.itbulu.com/$42、压缩静态数据
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html3、阻止指定IP访问
<Limit GET POST>
order allow,deny
deny from xx.xx.xx.xx
allow from all
</Limit>4、只允许自定义IP访问后台
AuthUserFile /dev/null
AuthGroupFile /dev/null
AuthName "Example Access Control"
AuthType Basic
<LIMIT GET>
order deny,allow
deny from all
allow from xx.xx.xx.xx
</LIMIT>我们需要在网站根目录中的wp-admin目录下新建一个.htaccess文件然后输入上面代码,替换自己的IP。
5、设置防盗链
RewriteEngine On
#Replace ?mysite\.com/ with your blog url
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?itbulu\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
#Replace /images/nohotlink.jpg with your “don’t hotlink” image url
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]6、定制特定用户跳转
RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.html$
RewriteCond %{REMOTE_ADDR} !^111\.111\.111\.111
RewriteRule $ /maintenance.html [R=302,L]/这个是用来暂停网站访问到维护页面的。如果用户直接跳转到maintenance.html页面,我们自己的IP设定后可以放行访问。
这里有没有我们需要的内容?如果你有用.htaccess 就可以这样选择需要的设置。