简体   繁体   English

使用mod_rewrite代理网址

[英]proxy a url using mod_rewrite

I have a domain for example 我有一个域名,例如

http://example.com 

and another domain 和另一个域

http://reallylargerdomain name.com

I want if sombody access http://example.com/projects then server should proxy data from other url. 我想如果sombody访问http://example.com/projects然后服务器应该代理来自其他网址的数据。 For this i created following .htaccess file 为此,我创建了以下.htaccess文件

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]

any idea what's going wrong? 什么出错了?

You need to make sure mod_proxy is loaded in your apache config. 您需要确保在apache配置中加载了mod_proxy。 Without it, the P flag sends the proxy request but there's nothing that can handle the target. 没有它, P标志发送代理请求,但没有任何东西可以处理目标。 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. 如果它们不同,该目录显然会被调整到您的路径。

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. 另外,请注意,如果规则中没有L标志,则在重写引擎完成之前,代理请求不会被发送回处理管道。 So if you have other rules after the proxy rule, they will be applied before the proxy happens. 因此,如果您在代理规则之后有其他规则,则会在代理发生之前应用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM