Apache rewrite

Apache rewrite

mod_rewrite简介和配置

  1. 实URL跳转隐藏真实地址 拟目录 域名跳转 防止盗链
  2. Apache配置支持httpd.conf配置.htaccess配置
  3. 启用rewrite #LoadModule rewrite_module modules/mod_rewrite.so去掉#
  4. 启用.htacess AllowOverride None修改AllowOverride All

mod_rewrite规则和使用

RewriteEngine on//启用
RewriteCond %{HTTP_HOST}!^www.php.com[NC]//判断主机
RewriteRule ^/(.*)http://www.php.com/[L]//跳转到php.com
防盗链
RewriteEngine on//启用
RewriteRule ^/test([0-9]*).html$/test.php?id=$1
//拟静态
RewriteRule ^/new([0-9]*)/$/new.php?id=1[R]
//拟目录

mod_rewrite规则修正符

  1. R 强制外部重定向
  2. F 禁用url,返回403http
  3. G 强制url为Gone 返回410状态码永久消失 搜索引擎不再来
  4. P 强制使用代理转发
  5. L 表明当前规则为最后一条停止分析以后规则重写
  6. N 重新从第一条 开始
  7. C 与下一条规则关联

  1. 如果规则正确匹配则以下修正符无效
  2. T=MIME-type(force MIME type)强制MIME类型
  3. NS只用于不是内部子请求
  4. NC不区分大小写
  5. QSA 追加请求字符串
  6. NE 不在输出转义特殊字符 %3d$1 等价于 =$1
posted @ 2016-01-25 20:38  charle94  阅读(134)  评论(0编辑  收藏  举报