Apache Url Rewrite 配置(php伪静态)

本人使用的apache版本是Apache/2.2.6检查 conf/httpd.conf 中是否存在如下一段代码:
#LoadModule rewrite_module modules/mod_rewrite.so
把LoadModule前边的#去掉,然后在网站根目录添加.htaccess(内写伪静态正则代码,这个文件可以在conf/httpd.conf 中的AccessFileName .htaccess指定),也可以直接在conf/httpd.conf中添加伪静态正则代码。然后重启apache(apache -k restart)就可以使用伪静态地址啦。如果没有安装 mod_rewrite,可以重新编译 Apache(或若为win系统建议重新安装),并在原有 configure 的内容中加入 –enable-rewrite=shared,然后再在 Apache 配置文件中加入正则代码。(另外让apache支持.htaccess的话,打开httpd.conf文件(在那里? APACHE目录的CONF目录里面),用文本编辑器打开后,查找Options FollowSymLinks

AllowOverride None

改为Options FollowSymLinks

AllowOverride All

就可以了。

)
1、mod_rewrite 简介和配置
Rewirte主要的功能就是实现URL的跳转和隐藏真实地址,基于Perl语言的正则表达式规范。平时帮助我们实现拟静态,拟目录,域名跳转,防止盗链等
2、mod_rewrite 规则的使用
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.iphpmysql.cn [NC]
RewriteRule ^/(.*) http:// www.iphpmysql.cn / [L]
——–
RewriteEngine on
RewriteRule ^/test([0-9]*).html$ /test.php?id=$1
RewriteRule ^/new([0-9]*)/$ /new.php?id=$1 [R]
3、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

Leave a comment

Your comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word