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
Can you try placing the 2nd rule before the 1st rule? Basically switch them.
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
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]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.