文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>URL Rewrite实现子目录绑定另外的网站

URL Rewrite实现子目录绑定另外的网站

时间:2008-03-13  来源:blau

要求是访问http://www.xxx.com/bbs/时看到的内容是http://bbs.yyy.com/,在apache的教程中有 关于Redirect的指令,但是只能实现跳转,跳转后浏览器中的域名也变了。要想实现浏览器中域名保存不变的话,需要用RewriteRule的P指令,调用apache的代理功能来实现。完整的rewrite规则如下:  

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteRule ^(.*)$ http://bbs.yyy.com/$1 [P,L]
</IfModule>

将上面的内容保存为.htaccess放置到www.xxx.com/bbs目录下就可以实现我们的目标了,RewriteRule完整的指令如下:

Flag Description
redirect[=status-code] Sends a status code between 300 and 400, specified by status-code. The default is 302.
R[=status-code] Same as "redirect"
forbidden Forces Stronghold to return a status code of 403 ("Forbidden"). This is useful for conditionally blocking URLs.
F Same as "forbidden"
gone Forces Stronghold to return a status code of 410 ("Gone").
G Same as "gone"
proxy Forces the substitution part through the proxy module. The substitution string must be a valid URI. This is useful as a sophisticated alternative to the ProxyPass directive.
P Same as "proxy"
last Force the rewrite process to end here
L Same as "last"
next Reruns the rewrite process, starting with the first instance of RewriteRule and using the outcome of the current rewrite process as new input
N Same as "next"
chain Chains the current rule with the next rule, provided that the current rule matches
C Same as "chain"
type=mime-type Forces Stronghold to return the file as the specified MIME type
T=mime-type Same as "type"
nosubreq Indicates that the current rule applies only if the current request is not an internal subrequest
NS Same as "nosubreq"
passthrough Passes the substitution to the next handler, which should immediately follow the current RewriteRule
PT Same as "passthrough"
skip=n Skips the next n rules in a sequence if the current rule matches
S=n Same as "skip"
env=VARIABLE:VALUE Sets the environment variable VARIABLE to the value VALUE
E=VARIABLE:VALUE Same as "env"

如果设置正确后,还不成功,并且apache的错误日志有

[Thu Mar 13 13:47:21 2008] [error] [client xx] Attempt to serve directory: proxy:http://bbs.yyy.com/
[Thu Mar 13 13:47:21 2008] [error] [client xx] File does not exist: proxy:http://www.xxx.com/bbs/header.gif, referer: http://bbs.yyy.com/

那是因为没有将apache的代理功能打开,需要修改httpd.conf配置文件,添加

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_http_module modules/mod_proxy_http.so

将代理功能打开,才能用p命令

 

相关阅读 更多 +
排行榜 更多 +
马里奥赛车世界游戏手机版下载

马里奥赛车世界游戏手机版下载

赛车竞速 下载
无畏契约皮肤开箱器手游下载

无畏契约皮肤开箱器手游下载

休闲益智 下载
旭日之城官方正版下载

旭日之城官方正版下载

策略塔防 下载