4

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?

kaysush
  • 4,797
  • 3
  • 27
  • 47

1 Answers1

3

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.

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • 1
    Just a note, the P flag does imply the L flag. http://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_p (this might have changes since answer was given) – Jeroen Nov 10 '14 at 08:33