2

Recently, I upgraded my Apache server from 2.0 to 2.2.24, but I have an issue with RedirectMatch.

My old RedirectMatch directive:

RedirectMatch ^/abc/abcd  /otherurl/someaction

In Apache 2.0, if we use HTTPS to access, eg. https://www.example.com/abc/abcd, it will redirect to https://www.example.com/otherurl/someaction.

But in apache 2.2.24, it returns http://www.example.com/otherurl/someaction (HTTP, not HTTPS) - it seems Apache has changed the request schema.

If I check the HTTP response by http watch, I find a difference between 2.0 and 2.2.24.

Under Apache 2.0 the Location HTTP response header is /otherurl/someaction - a relative path URL.

But on Apache 2.2.24 the Location header is http://www.example.com/otherurl/someaction - the full absolute URL.

Any idea for this issue?

MrWhite
  • 43,179
  • 8
  • 60
  • 84
fightf
  • 71
  • 1
  • 4
  • Could you add your entire configuration around `RedirectMatch`? If I understand your problem correct you miss the SSL part when redirect is made? – Qben Oct 10 '13 at 09:05
  • It could be that your `https` site is not enabled in Apache 2.2, thus making the `http` site the default one? – Qben Oct 10 '13 at 16:49
  • FWIW under Apache 2.0 an absolute target URL is strictly required, since Apache will not "fix" the target URL (ie. the value of the `Location` HTTP response header) to be absolute (this changed in Apache 2.2.6). If Apache does not make the target URL absolute then it is up to the user-agent to resolve the URL. In [RFC 2616](https://tools.ietf.org/html/rfc2616#page-135) (now superseded by [RFC 7321](https://tools.ietf.org/html/rfc7231#section-7.1.2) it was stated that the `Location` header must be absolute, hence why some "old" user-agents might not accept a relative URL. – MrWhite Aug 22 '16 at 10:29

1 Answers1

1

I think your problem is that Redirect changed from 2.0 to 2.2(.6). And according to documentation:

The old URL-path is a case-sensitive (%-decoded) path beginning with a slash. A relative path is not allowed. The new URL should be an absolute URL beginning with a scheme and hostname. In Apache HTTP Server 2.2.6 and later, 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.

I would suggest to change the rule to this if you just miss the https redirect:

RedirectMatch ^/abc/abcd https://www.example.com/otherurl/someaction

Hope it helps.

MrWhite
  • 43,179
  • 8
  • 60
  • 84
Qben
  • 2,617
  • 2
  • 24
  • 36
  • thanks your comments, but the hostname is dynamic, it's based on request, in mod_alias, how can i get the ${HTTP_Host} in request?? – fightf Oct 10 '13 at 15:42
  • How many hosts do we talk about? If it's just a couple you could hardcode them into different `VirtualHost` if you need it to be all dynamic you should consider using `mod_rewrite` and using a `RewriteRule` instead of `RedirectMatch`. – Qben Oct 10 '13 at 16:10
  • Agree, i think i have to change this rewrite rule by mod_rewrite. Again, Thanks your comments and suggestion. – fightf Oct 11 '13 at 01:25
  • 1
    As noted in the docs, "the scheme and hostname of the current server will be added" - so this should have worked unaltered on Apache 2.2.24. The problem is likely to have been caused by some other server config issue (eg. is SSL handled by Apache or a front-end proxy?). – MrWhite Aug 22 '16 at 10:15