一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

apache rewrite规则学习笔记

时间:2014-06-06 编辑:简简单单 来源:一聚教程网

Apache Rewrite 默认是需要打开的

Apache下的Rewrite配置主要有两种,一种是针对整个apache服务器的配置,此种配置的Rewrite规则是直接在httpd.conf下书写。配置步骤如下:

(1)去除httpd.conf文件中"#LoadModule rewrite_module modules/mod_rewrite.so"前面的"#"号;

(2)然后再在httpd.conf中书写如下规则:

RewriteEngine on

#当访问任何以t_开头,以.html结尾的文件时,将$1用与(.*)匹配的字符替换后,访问相应的test.php页面

例子:

 代码如下 复制代码

RewriteEngine on 打开引擎
RewriteRule test.html /test.php [L]
RewriteRule test.html?$ /tianqi.php?s1=&s2=&S3= [QSA,L] 用于多个参数的情况
RewriteRule tianqi-([0-9]+).html /tianqi.php?id=$1 [L]

正则找出不是六个文件的URL的模式,进行过滤

 代码如下 复制代码

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^/(.*) /index.asp$1 [L]

RewriteCond %{REQUEST_URI} ^/index.asp [NC,OR]
RewriteCond %{REQUEST_URI} ^/o.asp [NC,OR]
RewriteCond %{REQUEST_URI} ^/s.asp [NC,OR]
RewriteCond %{REQUEST_URI} ^/error.asp [NC,OR]
RewriteCond %{REQUEST_URI} ^/favicon.ico [NC,OR]
RewriteCond %{REQUEST_URI} ^/status.taobao [NC,OR]
RewriteCond %{REQUEST_URI} ^/app/thirdparty/webbox.asp [NC,OR]
RewriteCond %{REQUEST_URI} ^/static/ [NC]
RewriteRule ^.* - [L]

RewriteCond %{REQUEST_URI} !^/index.asp$
RewriteRule ^.* – [F,L]

热门栏目