Djave Djave - 2 months ago 15
Apache Configuration Question

Redirect pages which end in a nubmer

This is such a stupid question, I'm so close to solving it but regex is killing me – I'm using the JavaScript history api on various pages of a test.

Server side, I would like to redirect:

/test/1
/test/2
/test/3


All to

/test


So I am using

Redirect 301 /test/1 /test
Redirect 301 /test/2 /test
Redirect 301 /test/3 /test


This all works, but I would like to redirect

Redirect 301 /test/1000 /test


So, here is where I am going wrong, after some hacking, googling etc I'm using:

Redirect 301 /test/([0-9]+) /test


to replace all other lines of code, but it's totally failing. What's the line to match all
/test/{number}
so I can redirect them all at once?

Answer

Redirect doesn't support regex, but RedirectMatch does: httpd://apache.org/docs/current/mod/mod_alias.html#redirectmat‌​ch

It would read:

RedirectMatch 301 /test/[0-9]+ /test