您的位置:首页 > 运维架构 > Apache

Apache mod_rewrite规则重写的标志一览

2012-09-12 15:10 543 查看
Apache mod_rewrite规则重写的标志一览

1) R[=code](force redirect) 强制外部重定向

强制在替代字符串加上http://thishost[:thisport]/前缀重定向到外部的URL.如果code不指定,将用缺省的302 HTTP状态码。

2) F(force URL to be forbidden)禁用URL,返回403HTTP状态码。

3) G(force URL to be gone) 强制URL为GONE,返回410HTTP状态码。

4) P(force proxy) 强制使用代理转发。(内部代理)

5) L(last rule) 表明当前规则是最后一条规则,停止分析以后规则的重写。

6) N(next round) 重新从第一条规则开始运行重写过程。

7) C(chained with next rule) 与下一条规则关联
如果规则匹配则正常处理,该标志无效,如果不匹配,那么下面所有关联的规则都跳过。
8) T=MIME-type(force MIME type) 强制MIME类型

9) NS (used only if no internal sub-request) 只用于不是内部子请求

10) NC(no case) 不区分大小写

11) QSA(query string append) 追加请求字符串

12) NE(no URI escaping of output) 不在输出转义特殊字符

例如:RewriteRule /foo/(.*) /bar?arg=P1%3d$1 [R,NE] 将能正确的将/foo/zoo转换成/bar?arg=P1=zoo

13) PT(pass through to next handler) 传递给下一个处理

例如:

RewriteRule ^/abc(.*) /def$1 [PT] # 将会交给/def规则处理

Alias /def /ghi

14) S=num(skip next rule(s)) 跳过num条规则

15) E=VAR:VAL(set environment variable) 设置环境变量
===============================================

1、Apache中vhosts里相同的ServerName配置的生效顺序:第一匹配
在Apache的配置文件httpd.conf中,如果有相同的配置选项,应是后面的参数覆盖前面的参数(记得在手册以及网上这样说过,写本文时没有验证)。

然而在apache中Include conf/extra/httpd-vhosts.conf时,是从前面开始读取,当match到<VirtualHost >,且match到ServerName时,就不再向后面读了。如以下配置:
<VirtualHost *>

DocumentRoot /Docdir/ce

ServerName ce.cn

</VirtualHost>
<VirtualHost *>

DocumentRoot /Docdir/ce/ce.cn

ServerName ce.cn

</VirtualHost>
则应是匹配上面的一个配置,就是读/Docdir/ce下面的文件。

2、去NAS迁移
1、删除
#<IfModule mod_alias.c>
#       Alias /file/ "/mnt/efs/www/smartform/"
#</IfModule>

2、打开rewrite功能(必要时检查apache是否已经加载rewrite模块: ./apachectl -l)
在修改virtualhost.conf时,需要先打开rewrite功能:RewriteEngine On

3、添加RewriteRule
RewriteRule ^/file/(.*)   http://*****/download/www/smartform/$1 [L,P]

3、login
RewriteRule ^/a_group_uni_style_login:${a_intl_uni_connection_ssl_port}/(.*)$

http://style.a.com/$1 [L,P]
RewriteRule ^/ali_group_unicorn_style:${alibaba_intl_unicorn_connection_ssl_port}/(.*)$ http://style.aliunic.com/$1 [L,P]
4、在httpd.conf中将virtualhost.conf进来
<generate template="virtualhost.conf.vm" destfile="conf/virtualhost.conf" charset="GBK" />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mod_rewrite