引用
http://zd6.org/200607/apache-mod_rewrite-euay-ou-httpd-odhooooaucuaiooooau.html
在apache 官网上下载apache_2.2.13-win32-x86-openssl-0.9.8k.msi,安装
注:如果无法启动apache可在:
1.打开运行=》CMD
2.netstat -ano|findstr 80
3.tskill pid
在apache 的配置文档httpd.conf中添加重定向规则:
ServerAlias reymont.net
ServerAdmin liyang_sk@yahoo.com.cn
ServerName www.reymont.net
RewriteEngine On
#重定向/space/*
RewriteCond %{REQUEST_URI} ^/space/
RewriteRule /space/(.*) http://space.itpub.net/21315280/$1 [R=permanent,L]
#重定向/*
RewriteCond %{REQUEST_URI} !^/space/
RewriteRule /(.*) http://space.itpub.net/21315280/$1 [R=permanent,L]
附
Apache的RewriteRule规则详细介绍:
R[=code](force redirect) 强制外部重定向
强制在替代字符串加上http://thishost[:thisport]/前缀重定向到外部的URL.如果code不指定,将用缺省的302 HTTP状态码。
F(force URL to be forbidden)禁用URL,返回403HTTP状态码。
G(force URL to be gone) 强制URL为GONE,返回410HTTP状态码。
P(force proxy) 强制使用代理转发。
L(last rule) 表明当前规则是最后一条规则,停止分析以后规则的重写。
N(next round) 重新从第一条规则开始运行重写过程。
C(chained with next rule) 与下一条规则关联
如果规则匹配则正常处理,该标志无效,如果不匹配,那么下面所有关联的规则都跳过。
T=MIME-type(force MIME type) 强制MIME类型
NS (used only if no internal sub-request) 只用于不是内部子请求
NC(no case) 不区分大小写
QSA(query string append) 追加请求字符串
NE(no URI escaping of output) 不在输出转义特殊字符
例如:RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE] 将能正确的将/foo/zoo转换成/bar?arg=P1=zed
PT(pass through to next handler) 传递给下一个处理
例如:
RewriteRule ^/abc(.*) /def$1 [PT] # 将会交给/def规则处理
Alias /def /ghi
S=num(skip next rule(s)) 跳过num条规则
E=VAR:VAL(set environment variable) 设置环境变量
Rewrite规则表达式的说明:
. 匹配任何单字符
[chars] 匹配字符串:chars
[^chars] 不匹配字符串:chars
text1|text2 可选择的字符串:text1或text2
? 匹配0到1个字符
* 匹配0到多个字符
+ 匹配1到多个字符
^ 字符串开始标志
$ 字符串结束标志
\n 转义符标志
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/21315280/viewspace-615006/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/21315280/viewspace-615006/