1

Is it possible to implement a server-relative redirect using existing Apache features?

mod_alias does have a Redirect command, but that one always generates an absolute redirect even if configured like

Redirect /asdf /qwer

Also tried using mod_rewrite like this:

RewriteEngine On
RewriteRule /asdf(.*) /qwer$1 [R,L]

The end result of either of these settings is the same:

HTTP/1.0 302 Found
Location: http://my-host.blah.blah:20085/qwer

But what I really need is:

HTTP/1.0 302 Found
Location: /qwer

--- EDIT ---

Yes, I know this is against RFC spec. But all modern browsers support a relative redirect, and I really need it for a temporary fix.

1 Answer 1

4

That is the way Redirect works; from the manual:

The new URL should be an absolute URL beginning with a scheme and hostname, but a URL-path beginning with a slash may also be used, in which case the scheme and hostname of the current server will be added.

From RFC 2616, section 14.30:

The field value consists of a single absolute URI.

3
  • 1
    It may be an incorrect redirect, but all modern browsers support it. See en.wikipedia.org/wiki/HTTP_location
    – rustyx
    Jul 24, 2012 at 9:55
  • I never said it was incorrect, and his question was whether apache supports it. In short, no :)
    – adaptr
    Jul 24, 2012 at 9:56
  • His question was, importantly, not whether apache supports it, but [whether] it is possible…using existing Apache featureswhich it is. I think this is not only a non-answer, but incorrect. Jan 7, 2020 at 18:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .