skip to Main Content

I want to setup 301 redirects for requests from: /category/groceries-and-everyday/household/

Redirecting them to: /category/household/

I have the following rules set up for these requests:

# The following is to redirect old urls
RedirectMatch 301 ^/category/groceries-and-everyday/household/$ /category/household/

# This is our rewrite rule for SEO friendly URLs
RewriteRule ^category/(.*)/$ /category_pages/category.php?category_string=$1&rewrite=1 [NC,QSA]

Now when I load /category/groceries-and-everyday/household

I get bounced to: /category/household/?category_string=groceries-and-everyday/household&rewrite=1

I want this to bounce only to: /category/household/

Can somebody please explain why this behaviour is occurring and what changes I should make to achieve my desired result.

Many thanks

3

Answers


  1. Chosen as BEST ANSWER

    Slight adaption on Starkeen's answer.

    Changing the second htaccess rule to have the following rewrite condition appears to work.

    RewriteCond %{REQUEST_URI} !^/category/groceries-and-everyday/household/(.*)
    RewriteRule ^category/(.*)/$ /category_pages/category.php?category_string=$1&rewrite=1 [NC,QSA]
    

  2. Can you try placing the 2nd rule before the 1st rule? Basically switch them.

    Login or Signup to reply.
  3. You need to exclude the uri category/household from your rule :

    RewriteCond %{REQUEST_URI} !^/category/household    RewriteRule ^category/(.*)/$ /category_pages/category.php?category_string=$1&rewrite=1 [NC,QSA]
    

    otherwise your rewrite pattern ^category/(.*)/$ will also rewrite it to /category_pages/category.php?category_string=$1&rewrite=1

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search