.htaccess 301 redirect results in unusual behavior

I am adding some 301 redirects to a site, the syntax I am using works for nearly all the redirects, except for a a few. It seems unusual to me that the syntax I am using works for some and not others.

An example would be:

Read More
RedirectMatch 301 /faqs/general(.*) /general-faq/$1

this redirects to the specified folder correctly, but this:

RedirectMatch 301 /faqs/program(.*) /general-faq/$1

This redirects to the folder /program/

What is the deal?

I am using WordPress as a CMS, I have included these redirects in the correct location within the htaccess file. Redirects that are commented out are the ones that are broken.

    # BEGIN WordPress

# WPhtc: Begin Custom htaccess
Options +FollowSymLinks

RewriteRule ^academics/courses.*$ http://www.bridgesboysacademy.com/course-curriculum/ [R=301,L]

RedirectMatch 301 /emotional(.*) /emotional-growth/$1

RedirectMatch 301 /emotional/family(.*) /family-participation/$1

RedirectMatch 301 /emotional/community(.*) /community-meetings/$1

RedirectMatch 301 /campus/athletics(.*) /sports-recreation/$1

RedirectMatch 301 /emotional/adventure(.*) /outdoor-adventure/$1

#RedirectMatch 301 /emotional/addiction(.*) /addiction-studies/$1

RedirectMatch 301 /student(.*) /student-profile/$1

#RedirectMatch 301 /student/questionnaire(.*) /student-profile/$1

RedirectMatch 301 /campus(.*) /campus-life/$1

#RedirectMatch 301 /campus/schedule(.*) /daily-schedule/$1

RedirectMatch 301 /faqs(.*) /general-faq/$1

RedirectMatch 301 /faqs/general(.*) /general-faq/$1

#RedirectMatch 301 /faqs/program(.*) /general-faq/$1

RedirectMatch 301 /faqs/academic(.*) /general-faq/$1

RedirectMatch 301 /campus(.*) /campus-life/$1

#RedirectMatch 301 /admissions(.*) /admissions-faq$1
#RedirectMatch 301 /admissions/application(.*) /admissions-faq$1
#RedirectMatch 301 /admissions/testimonials(.*) /admissions-faq/$1
#RedirectMatch 301 /admissions/fees(.*) /admissions-faq/$1
#RedirectMatch 301 /admissions/financial(.*) /admissions-faq/$1
#RedirectMatch 301 /faqs/tuition(.*) /admissions-faq/$1

RedirectMatch 301 /about/facts(.*) /about$1

RedirectMatch 301 /about/accreditations(.*) /accreditation$1

RedirectMatch 301 /about/staff(.*) /staff$1

RedirectMatch 301 /academics/bios(.*) /staff$1

RedirectMatch 301 /about/careers(.*) /career-opportunities$1

RedirectMatch 301 /parents(.*) https://crm.bestnotes.com/portal/bridgesacademy$1
# WPhtc: End Custom htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Related posts

Leave a Reply

1 comment

  1. You’ve got these redirects backwards:

    RedirectMatch 301 /faqs(.*) /general-faq/$1
    
    RedirectMatch 301 /faqs/general(.*) /general-faq/$1
    
    #RedirectMatch 301 /faqs/program(.*) /general-faq/$1
    
    RedirectMatch 301 /faqs/academic(.*) /general-faq/$1
    

    The first redirect will match anything the other 3 does, so essentially, the last 3 do nothing. You need to place the most general one (the first) at the end:

    RedirectMatch 301 ^/faqs/general(.*) /general-faq/$1
    RedirectMatch 301 ^/faqs/program(.*) /general-faq/$1 
    RedirectMatch 301 ^/faqs/academic(.*) /general-faq/$1
    RedirectMatch 301 ^/faqs/(.*) /general-faq/$1
    

    You should also add a ^ to the beginning of your patterns. This way, it won’t randomly match against something that’s further along in the path, e.g. /something/faqs/something/

    Additionally, you need to change the “emotional” ones to behave the same:

    RedirectMatch 301 ^/emotional/family(.*) /family-participation/$1
    RedirectMatch 301 ^/emotional/community(.*) /community-meetings/$1
    RedirectMatch 301 ^/emotional/adventure(.*) /outdoor-adventure/$1
    RedirectMatch 301 ^/emotional/(.*) /emotional-growth/$1
    

    Notice that I added a / to the end of the “emotional” in the last redirect. You need to do the same with a few other redirects:

    RedirectMatch 301 ^/student/(.*) /student-profile/$1
    RedirectMatch 301 ^/campus/(.*) /campus-life/$1
    

    You should also add a ^ to the beginning of your patterns.