使用mod_rewrite代理网址 [英] proxy a url using mod_rewrite

查看:70
本文介绍了使用mod_rewrite代理网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有一个域

http://example.com 

和另一个域

http://reallylargerdomain name.com

我想如果有人访问 http://example.com/projects ,那么服务器应该代理其他网址中的数据. 为此,我创建了以下.htaccess文件

I want if sombody access http://example.com/projects then server should proxy data from other url. For this i created following .htaccess file

Rewrite on
RewriteRule ^projects/$ http://reallylargedomainname.com [P]

这不起作用,但是当我将其更改为跟随它时

this is not working but when i change it to following it works

Rewrite on
RewriteRule ^projects/$ http://reallylargedomainname.com [R=301,L]

知道发生了什么事吗?

推荐答案

您需要确保在您的apache配置中加载了mod_proxy.没有它,P标志将发送代理请求,但是没有任何东西可以处理目标.看起来像这样:

You need to make sure mod_proxy is loaded in your apache config. Without it, the P flag sends the proxy request but there's nothing that can handle the target. It's going to look something like this:

LoadModule  proxy_module modules/mod_proxy.so

如果目录不同,显然目录将被调整到您的路径.

The directory is obviously going to be tweaked to your paths if they are different.

此外,请注意,如果您的规则中没有L标志,则在重写引擎完成之前,代理请求不会被发送回处理管道.因此,如果您在代理规则之后还有其他规则,则会在代理发生之前应用它们.

Additionally, note that without the L flag in your rule, the proxy request won't be sent back into the processing pipeline until the rewrite engine is finished. So if you have other rules after the proxy rule, they will be applied before the proxy happens.

这篇关于使用mod_rewrite代理网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆