.htaccess的应用实例

.htaccess是一个非常强大的分布式配置文件,学会使用.htaccess,对网站用户来说,可以实现众多的功能。这里我们可以罗列一下通过修改.htaccess文件来增强网站的功能的一些有用实例。

feed的重定向设置:
RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds2.zl5.info/xxx [R=302,NC,L]

在wordpress的url中去除/category/
RewriteRule ^category/(.+)$ http://www.zl5.info/$1 [R=301,L]

使用浏览器缓存加速wordpress访问速度
FileETag MTime Size

ExpiresActive on
ExpiresDefault "access plus 1 year"

开启gzip压缩
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/html


把带有日期格式的永久链接形式重定向到/%postname%/格式

RedirectMatch 301 /([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ http://www.zl5.info/$4

阻止没有referrer requests的评论减少垃圾评论
RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post.php*
RewriteCond %{HTTP_REFERER} !.*zl5.info.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]

重定向访客到维护页面

RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.html$
RewriteCond %{REMOTE_ADDR} !^123.123.123.123
RewriteRule $ /maintenance.html [R=302,L]

保护您的博客不被盗链
RewriteEngine On
#Replace ?xxx.com/ with your blog url
RewriteCond %{HTTP_REFERER} !^http://(.+.)?xxx.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]

只允许固定的ip地址访问wp-admin
AuthUserFile /dev/null
AuthGroupFile /dev/null
AuthName "Example Access Control"
AuthType Basic

order deny,allow
deny from all
allow from xxx.xxx.xxx.xxx

屏蔽固定ip访问
order allow,deny
deny from xxx.xxx.xxx.xxx
allow from all

转载于:https://www.cnblogs.com/ado-geek/archive/2012/07/26/2609666.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值