I am using APACHE server and I want to redirect the url to home page if third parameter is invalid number. Code I have written is ::
RedirectMatch 302 ^/app/([a-zA-Z0-9_-]+)/([a-zA-Z_-]+)/?$ /
But its not working. In short:
www.xyz/app/test/3434 :: should pass
www.xyz/app/test/best :: should fail
www.xyz/app/test/34kkk34 :: should fail
You want to redirect when the last part is not a number. Stated otherwise, redirect when there's a non digit somewhere. To get this, you must first match any character including digits.
^/app/[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]*[a-zA-Z_-][a-zA-Z0-9_-]*/?$
Since you don't use any parts of the request in the target URL, there's also no need to capture anything ()
.
If you don't care about the particular characters, you can simplify the regular expression and just use .*
instead of [a-zA-Z0-9_-]*
, e.g.
^/app/.+?/.*?[^0-9].*/?$
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments