Prashant Patel Prashant Patel - 3 months ago 9
Apache Configuration Question

redirect URL with and without closing SLASH (symbol)

I need to redirect

example.org/folder1
&
example.org/folder1/
to
example.org/file.html


please see my code

Redirect 301 /folder1/ /file.html


this code only matches
example.org/folder1/
and ignores urls without closing
/
how can I make it work in both cases with and without
/
. Without having to repeat code twice!?

I also need it to NOT be case sensitive.

thank you sir

Answer

You can use RedirectMatch and make the trailing slash optional using ? char

RedirectMatch 301 ^/folder1/?$ /file.html
Comments