当前位置: 移动技术网 > IT编程>开发语言>PHP > PHP伪静态Rewrite设置之APACHE篇

PHP伪静态Rewrite设置之APACHE篇

2019年03月20日  | 移动技术网IT编程  | 我要评论
 一、apache配置:   1、支持httpd.conf 配置 2、支持目录 .htaccess配置(一种"分布式配置"文件针对虚拟空间,空间商

 一、apache配置:
 
1、支持httpd.conf 配置
2、支持目录 .htaccess配置(一种"分布式配置"文件针对虚拟空间,空间商不让修改apache配置文件)
 
启用rewrite(httpd.conf)
(有时候options indexes followsymlinks会出问题,只需要配置options all即可)

loadmodule rewrite_module modules/mod_rewrite.so

 
启用.htaccess
allowoverride none    修改为:allowoverride all
 
二、mod_rewrite 规则:
例如:

rewriteengine on              ->启动rewrite引擎
 
rewriterule ^/test([0-9]*).html$ /test.php?id=$1    ->指访问test加任意字段.html都能跳转到test.php    正则匹配的字段存放在虚拟内存匹配$1

 
三、mod_rewrite规则修正符
 
1) r 强制外部重定向
2) f 禁用url,返回403http状态码。
3) g 强制url为gone,返回410http状态码。
4) p 强制使用代理转发。
5) l 表明当前规则是最后一条规则,停止分析以后规则的重写。
6) n 重新从第一条规则开始运行重写过程。
7) c 与下一条规则关联
 
如果规则匹配则正常处理,以下修正符无效
 
8) t=mime-type(force mime type) 强制mime类型
9) ns  只用于不是内部子请求
10) nc 不区分大小写
11) qsa 追加请求字符串
12) ne 不在输出转义特殊字符   \%3d$1  等价于 =$1
 
 
例如:

rewriterule ^/new([0-9]*)/$ /new.php?id=$1 [r]

 
 
简单小范例:

rewriteengine on
rewriterule ^/in(.*).html$ /index.php

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网