linux apache 重写,Linux 系统 Apache mod_rewrite 规则重写的标志一览

Apache mod_rewrite正直

重写的符号

一览

R[=code](force redirect) 逼迫

外部重定向

逼迫

在更换

字符串加上[: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) 设置环境

变量

应用

mod_rewrite时常用的做事器变量:

HTTP headers:HTTP_USER_AGENT, HTTP_REFERER, HTTP_COOKIE, HTTP_HOST, HTTP_ACCEPT

connection & request: REMOTE_ADDR, QUERY_STRING

server internals: DOCUMENT_ROOT, SERVER_PORT, SERVER_PROTOCOL

system stuff: TIME_YEAR, TIME_MON, TIME_DAY

RewriteRule正直

表达式的阐发

. 匹配任何单字符

[chars] 匹配字符串:chars

[^chars] 不匹配字符串:chars

text1|text2 可选择的字符串:text1或text2

? 匹配0到1个字符

* 匹配0到多个字符

+ 匹配1到多个字符

^ 字符串起头符号

$ 字符串收场

符号

\n 转义符符号

反向引用 $N 用于 RewriteRule 中匹配的变量调用(0 <= N <= 9)

反向引用 %N 用于 RewriteCond 中末了

一个匹配的变量调用(1 <= N <= 9)

RewriteCond适用的符号

‘nocase|NC’ (no case)漠视

巨细

‘ornext|OR’ (or next condition)逻辑或,可以同时匹配多个RewriteCond条件

RewriteRule适用的符号

‘redirect|R [=code]’ (force redirect)欺凌

重写为基于http开头的外部转向(留意

URL的变动) 如:[R=301,L]

‘forbidden|F’ (force URL to be forbidden)重写为拦阻

拜访

‘proxy|P’ (force proxy)重写为通过署理

拜访的http路径

‘last|L’ (last rule)末了

的重写正直

符号

,假如

匹配,不再推行

以后的正直

‘next|N’ (next round)循环同一个正直

,直到不能满意

匹配

‘chain|C’ (chained with next rule)假如

匹配该正直

,则连续

下面的有Chain符号

的正直

‘type|T=MIME-type’ (force MIME type)指定MIME范例

‘nosubreq|NS’ (used only if no internal sub-request)假如

是内部子哀求则跳过

‘nocase|NC’ (no case)漠视

巨细

‘qsappend|QSA’ (query string append)附加查询字符串

‘noescape|NE’ (no URI escaping of output)拦阻

URL中的字符主动

转义成%[0-9]+的形式。

‘passthrough|PT’ (pass through to next handler)将重写结果运用

于mod_alias

’skip|S=num’ (skip next rule(s))跳过下面几个正直

‘env|E=VAR:VAL’ (set environment variable)添加环境

变量

实战

例子:

RewriteEngine on

RewriteCond %{HTTP_USER_AGENT} ^MSIE [NC,OR]

RewriteCond %{HTTP_USER_AGENT} ^Opera [NC]

RewriteRule ^.* – [F,L] 这里”-”表示没有变更

,涉猎

器为IE和Opera的访客将被拦阻

拜访。

例子:

RewriteEngine On

RewriteBase /test

RewriteCond %{REQUEST_FILENAME}.php -f

RewriteRule ([^/]+)$ /test/$1.php

#for example: /test/admin => /test/admin.php

RewriteRule ([^/]+)\.html$ /test/$1.php [L]

#for example: /test/admin.html => /test/admin.php

限定

目次

只能表现

图片

< IfModule mod_rewrite.c>

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !^.*\.(gif|jpg|jpeg|png|swf)$

RewriteRule .*$ – [F,L]

< /IfModule>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值