Apache的rewrite模块(url重写模块)配置
2009-06-29 16:53
741 查看
1,首先检查是否已安装rewrite模块: cat httpd.conf | grep rewrite LoadModule rewrite_module modules/mod_rewrite.so 2,生成伪静态html连接: (1)生成伪静态html 在<VirtualHost>段最后加入 RewriteEngine on RewriteRule /goods([0-9]+).html /goods.php?id=$1 [PT] 更标准的写法为: RewriteRule ^(.*)/goods([0-9]+).html$ $1/goods.php?id=$2 [PT] 更简洁的写法: /goods(\d+)\.html /goods\.php\?id=$1 第一个(0-9]+)对应参数$1,以此类推第二个对应$2 举例: RewriteRule /forum-([0-9]+)-([0-9]+)\.html /forumdisplay.php?fid=$1&page=$2 [PT] 测试http://www.xxx.com/goods1.html 是否与/goods.php?id=1的内容相同 最后将所有链接换成设置后的伪静态html地址方式 [PT]:url全局转换,即转换过的goods31.html对应goods.php?id=31 (默认就是这个不加参数) [R]: url重定向 即使用goods31.html访问时跳转到goods.php?id=31 3,防盗链: RewriteCrond %{HTTP_HOST} !upkiller.com [R=301,L] RewriteRule ^(.*)$ http://www.upkiller.com/warning.html [R=301,L] 把不是来自upkiller.com的请求重定向到http://www.upkiller.com/ 更好的做法: RewriteCond %{HTTP_REFERER} !^http://(www\.)?upkiller\.com/.*$ [NC] RewriteRule \.(mp3|rar|jpe|gif)$ http://www.upkiller.com/warning.jpg [R=301,L] 4,防百度爬虫: RewriteCond %{HTTP_USER_AGENT} ^Baiduspider [OR] RewriteRule ^(.*)$ http://www.google.com/ [R=301,L] 把来自百度的爬虫转到goole |
相关文章推荐
- apache启用rewrite重写模块配置伪静态
- apache url重写模块rewrite_module使用方法
- 在Apache中使用mod_rewrite模块重写URL
- apache 配置rewrite模块,URL中隐藏index.php
- Apache模块 mod_rewrite 及 初级URL重写指南
- iis url重写模块 2 Rewrite
- 解决URL中包含“%2F”导致Apache地址重写mod_rewrite失效的问题
- Apache利用.htaccess文件重写URL隐藏入口,模块名,实现伪静态
- Ubuntu Server 14.04 & Apache2.4 虚拟主机、模块重写、隐藏入口文件配置
- Apache配置之url重写
- .htaccess Rewrite apache重写和配置
- 配置Apache Httpd Server 2.2 Virtual Host UrlRewrite
- 深度理解apache 重写模块rewrite_mod,重写不再犯错
- Apache模块详解-mod_rewrite重写模块
- Apache Rewrite重写模块(二):10个实例详细分析
- apache配置URL重写
- Apache Rewrite模块重写功能开启及检测实现
- apache的url_rewrite地址重写中得到问号后面的参数
- 利用apache的mod_rewrite做URL规则重写
- wamp win2003 drupal配置apache下url地址重写