博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
.htaccess的应用实例
阅读量:6981 次
发布时间:2019-06-27

本文共 1792 字,大约阅读时间需要 5 分钟。

.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

你可能感兴趣的文章
转:浅谈Linux的内存管理机制
查看>>
boolean
查看>>
ピエタ~幸せの青い鳥~相关
查看>>
Eclipse for Tricore 的安装方法
查看>>
IE下javascript的console方法
查看>>
机器学习 LR getA()
查看>>
java如何读写json文件
查看>>
py 的 第 31 天
查看>>
文件上传至阿里云
查看>>
HDU 1711 Number Sequence (KMP 入门)
查看>>
Win2008远程多用户登陆的配置方法
查看>>
Oracle回收站
查看>>
JavaSript模块化 && AMD CMD 详解.....
查看>>
react构建淘票票webapp,及react与vue的简单比较。
查看>>
swift(一)基础变量类型
查看>>
使用XHProf分析PHP性能瓶颈(二)
查看>>
BZOJ 3420: Poi2013 Triumphal arch
查看>>
ubuntu12.04 alternate win7 双系统安装
查看>>
C#语言 数组
查看>>
MySQL数据库开发规范-EC
查看>>