Search code examples
.htaccessmod-rewritemod-proxy

.htaccess - mod_dir with RewriteRule Proxy


I am running into an unusual problem. I have a series of sites that art pointing to my hosted site, for example purposes:

http://sub.mydomain.com/help/

All these other sites use this .htaccess file

Options +FollowSymLinks -Indexes
RewriteEngine on

RewriteRule ^(.*)$ http://sub.mydomain.com/$1 [P,E=Proxy-Host:sub.mydomain.com]

It is working great for the most part. Let's call one of these other domains "sub.otherdomain.com".

If I go to http://sub.otherdomain.com/help/ it works fine.

If I go to http://sub.otherdomain.com/help it is getting redirected to http://sub.mydomain.com/help/

The reason is because mod_dir is redirecting the / to the main domain.

I want it to redirect the / to the proxied domain.

Any ideas?


Solution

  • You'll need to set ProxyPassReverse. This can't be done in htaccess. You need to add this in the <VirtualHost> section.