proxy a url using mod_rewrite

限于喜欢 提交于 2019-12-12 12:23:54

问题


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. 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]

any idea what's going wrong?


回答1:


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.

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.



来源:https://stackoverflow.com/questions/12103931/proxy-a-url-using-mod-rewrite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!