0

I am trying to redirect something like this but I just get a 404. All my others work except the ones with a + in them. I tried escaping the + as well but doesn't work.

RedirectMatch 302 /\+\123456788 https://example.com/
MrWhite
  • 23,175
  • 4
  • 44
  • 71
Waterfall
  • 190
  • 8
  • 1
    What URL are you going to and what do you expect to happen? – Amit Verma Dec 09 '20 at 11:55
  • @AmitVerma, it is going to https://example.com/+123456788 (which I assume was used for a telephone number but not done correctly as should be tel:+12345678) and that needs to redirect to the home page – Waterfall Dec 09 '20 at 11:56
  • @CBroe, should it then be `302 /\s123456788` ? – Waterfall Dec 09 '20 at 11:58
  • 2
    does it work? `RedirectMatch 302 /\+123456789 /` – Amit Verma Dec 09 '20 at 12:00
  • 1
    @CBore thats a literal `+` char not the space – Amit Verma Dec 09 '20 at 12:01
  • @AmitVerma, it seems that is working! – Waterfall Dec 09 '20 at 12:04
  • What is the the URL you are trying to match? You've only shown the directive/regex (which is incorrect). And if it's supposed to go "to `https://example.com/+123456788`" - then this directive is not going to do that. – MrWhite Dec 09 '20 at 12:18
  • 2
    @CBroe The `+` is only an encoded _space_ when used in the query string part of the URL. When used in the URL-path it's just a literal character. – MrWhite Dec 09 '20 at 12:18
  • 1
    @MrWhite, the url I am trying to match is `https://example.com/+123456788` and because it doesn't exist it should redirect to the home page `https://example.com` – Waterfall Dec 09 '20 at 17:38

1 Answers1

3

Could you please try following, not tested it yet, should work I believe. We need to escape + to treat it as a literal character. Also we need not to escape 1 here since its a digit.

RedirectMatch 302 ^/\+123456788/?$ https://example.com/
RavinderSingh13
  • 101,958
  • 9
  • 41
  • 77
  • 2
    "not to escape 1" - Yes. Specifically, `\123` is seen as an octal escape sequence that matches a literal `S` (probably not what the OP intended). – MrWhite Dec 09 '20 at 12:46
  • 1
    @MrWhite, awesome, thank you for sharing(well I thought from regex point of view more that 1 is not having special meaning), that's a learning for me too, cheers. – RavinderSingh13 Dec 09 '20 at 12:48