user1111929
user1111929

Reputation: 6097

Can one mimic a cross-domain mod-rewrite rule?

Is it possible to mimic a rewrite rule, that will make //domain1.com/anypagename.php?key=value redirect to //domain1.com/anypagename.php?key=value, given that domain1.com and domain2.com reside on different host machines? Regular mod-rewrite doesn't allow this, but perhaps a combination of rewrite rules making everything point to the same file and have that file forward it, can mimic this?

The reason why I want to do this is because domain1 is a well-trusted subdomain of a large domain, so we want to keep this for marketing purposes, but we cannot change the DNS records and the associated hosting service is so terrible that we want the actual website to run on our own servers (and domain2.com is a regular domain under our control).

Methods using .htaccess, PHP etc. are all good, but it is important that both GET and POST request to arbitrary pages (with arbitrary ?key=val&key2=val2 arguments) on domain1 are correctly processed on domain2 and displayed as if they were actually regular pages on domain1.

Upvotes: 0

Views: 168

Answers (1)

Olaf Dietsche
Olaf Dietsche

Reputation: 74048

I haven't tried this, but the P|proxy flag comes to mind

For example, if you wanted all image requests to be handled by a back-end image server, you might do something like the following:
...

In your case, when domain1.com and domain2.com are set up identically, this could be

RewriteRule ^ http://domain2.com%{REQUEST_URI} [P]

However, note also

Performance warning

Using this flag triggers the use of mod_proxy, without handling of persistent connections. This means the performance of your proxy will be better if you set it up with ProxyPass or ProxyPassMatch


So ProxyPass might be the better alternative

ProxyPass / http://domain2.com

But there's a drawback to this one too, you cannot use it in an .htaccess file. This works only, if you have access to the main or virtual host configuration.

Upvotes: 1

Related Questions