简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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