WEB开发网
开发学院服务器WEB服务器Apache mod_rewrite模块详解 阅读

mod_rewrite模块详解

 2008-10-23 00:00:00 来源:WEB开发网   
核心提示: 如果你的网站服务器URL不是与物理文件路径直接对应的, 而又需要使用RewriteRule指令,mod_rewrite模块详解(5), 则必须在每个对应的.htaccess文件中指定RewriteBase,举例, 而且这样的过程在Apache内部也为其他许多操作所使用, 所以,目录级配置文件内容

如果你的网站服务器URL不是与物理文件路径直接对应的, 而又需要使用RewriteRule指令, 则必须在每个对应的.htaccess文件中指定RewriteBase。

举例,目录级配置文件内容如下:

#

# /abc/def/.htaccess -- per-dir config file for directory /abc/def

# Remember: /abc/def is the physical path of /xyz, i.e., the server

# has a 'Alias /xyz /abc/def' directive e.g.

#

RewriteEngine On

# let the server know that we were reached via /xyz and not

# via the physical path prefix /abc/def

RewriteBase /xyz

# now the rewriting rules

RewriteRule ^oldstuff.html$ newstuff.html

上述例子中,对/xyz/oldstuff.html 的请求被正确地重写为物理的文件/abc/def/newstuff.html.

For Apache Hackers

以下列出了内部处理的详细步骤:

Request:

/xyz/oldstuff.html

Internal Processing:

/xyz/oldstuff.html -> /abc/def/oldstuff.html (per-server Alias)

/abc/def/oldstuff.html -> /abc/def/newstuff.html (per-dir RewriteRule)

/abc/def/newstuff.html -> /xyz/newstuff.html (per-dir RewriteBase)

/xyz/newstuff.html -> /abc/def/newstuff.html (per-server Alias)

Result:

/abc/def/newstuff.html

虽然这个过程看来很繁复,但是由于目录级重写的到来时机已经太晚了, 它不得不把这个(重写)请求重新注入到Apache核心中,所以Apache内部确实是这样处理的。 但是:它的开销并不象看起来的那样大,因为重新注入完全在Apache服务器内部进行, 而且这样的过程在Apache内部也为其他许多操作所使用。 所以,你可以充分信任其设计和实现是正确的。

上一页  1 2 3 4 5 6 7 8 9 10  下一页

Tags:mod rewrite 模块

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接