#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2005
    Posts
    266
    Rep Power
    10

    Redircting certain path plus anything in it to a 404 and then to the home page


    I'm trying to redirect everything from for example:

    Code:
    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..

    Code:
    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.
  2. #2
  3. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1100
    I believe Redirect directives work against the request uri, which includes the leading forward slash, but your pattern doesn't account for that:
    Code:
    RedirectMatch 404 ^/[a-zA-Z]{2}/My_Dir/.*$
    If you're using mod_rewrite, those directives will apply first, so you're pattern may not match as a result, or you may never be reaching the Redirect directive at all. If that's the case, you can do this with a RewriteRule:
    Code:
    RewriteRule ^[a-zA-Z]{2}/My_Dir/.*$ - [NC,F]
    Note that the NC flag takes care of your case issue.
    # Jeremy

    Explain your problem instead of asking how to do what you decided was the solution.

IMN logo majestic logo threadwatch logo seochat tools logo