I’m trying to redirect everything from for example:
mycomain.com/ST/My_Dir/anything
Where ST is equal to a state abbreviation and anything is equal to anything.
I tried the below code in my .htaccess file but it doesn’t work..
ErrorDocument 404 /index.php
RedirectMatch 404 ^[a-zA-Z]{2}/My_Dir/.*$
Also, is there a way that I can make My_Dir case-insensitive? I know how to do this in PHP but just not sure if it’s the same here.
If you want to force specific urls to return 404 response, you can use:
instead of the
RedirectMatchrule. Also to throw a 403 Forbidden you can just useFIn both examples, the
NCflag makes the match case insensitive. Also I would not recommend using your homepage (/index.php) as your 404 page, better that you make a custom 404.php and set yourErrorDocumentto that.