Jellicle
Jellicle

Reputation: 30296

Apache mod_rewrite: rewrite HOSTNAME without redirect

It's clear to me how to perform a rewrite in apache using mod_rewrite, and I can rewrite the path without returning a redirect, but can I also rewrite the hostname without returning a redirect?

(I desire for the application that receives the request to make use of a particular hostname, but I don't want API users to need to follow any redirects.)

The Absolute URL section of the mod_rewrite documentation says something which makes it appear that a change of hostname will return a redirect be default:

If an absolute URL is specified, mod_rewrite checks to see whether the hostname matches the current host. If it does, the scheme and hostname are stripped out and the resulting path is treated as a URL-path. Otherwise, an external redirect is performed for the given URL.

Upvotes: 2

Views: 1447

Answers (1)

Jellicle
Jellicle

Reputation: 30296

Well, at this point, I'm using a reverse proxy and manually overriding the Host HTTP header:

<VirtualHost *:443>
  ServerName old.domain.org
  SSLProxyEngine on
  ProxyRequests off
  ProxyPassMatch   ^/ https://new.domain.org/
  ProxyPassReverse ^/ https://new.domain.org/
  ProxyPreserveHost off
  RequestHeader set Host new.domain.org
  Header set Host old.domain.org
</VirtualHost>

...but I'd like to accomplish my goal with mod_rewrite so that I can make use of an <If> block.

Upvotes: 1

Related Questions