Question

I just started working with Redirect 301 recently on a Wordpress site. All of my Redirects have been working fine until I got to a section where I moved a parent under another parent and all the children followed. When I set up the Redirect 301 for the parent it worked but all the ones underneath it are having issues. All of my other redirects work it's only the new ones that are having issues I'll include these along with some of the old ones below.

I've omitted the http:// Website name from the absolute links because I can only post 2 links.

Working:

redirect 301 /category/best-cd-rates/keybank-cd /keybank/reviews/cd/
redirect 301 /category/best-cd-rates/metlife-cds-best-cd-rates /metlife/reviews/cd/
redirect 301 /the-pinnacle-of-bank-rates /golf-savings-bank/reviews/cd/

Not Working:

redirect 301 /bank-ratings/ally-bank-rating/cd-account/ /ally-bank/ratings/cd/
redirect 301 /bank-ratings/amegy-bank-ratings/amegy-bank-customer-service-ratings /amegy-bank/ratings/customer-service/

The only part not working is the last part of the relative link won't change to the last part of the absolute path.

Meaning the url should look like:

/amegy-bank/ratings/customer-service/

But actually looks like:

/amegy-bank/ratings/amegy-bank-customer-service-ratings/

I made sure to edit the url's of the sites that I was redirecting to to the correct url that I wanted.

If anyone has a better way of describing my problem that could also help since I've been banging my head against the wall searching for exactly what the problem is called.

Thanks in advance

Part of the .htaccess file

<IfModule mod_rewrite.c>
RedirectMatch 301 go up here
RewriteEngine On

The full answer is below in the answer and comments basically I just needed to use a Redirectmatch 301 in the right place.

Was it helpful?

Solution

You need to use RedirectMatch to make sure you don't match unwanted URI:

RedirectMatch 301 ^/bank-ratings/ally-bank-rating/cd-account/$ /ally-bank/ratings/cd/
RedirectMatch 301 ^/bank-ratings/amegy-bank-ratings/amegy-bank-customer-service-ratings$ /amegy-bank/ratings/customer-service/
  • Make sure to test it in a new browser to avoid 301 caching issues.
  • RedirectMatch 301 rules must appear before RewriteEngine On
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top