Forum Topic: How to redirect pages that have multiple URL possibilitiess?

Forum: .htaccess Forum : Redirecting • Posted by Kevin Meronuk • Updated:

I've helped a client migrate their website from Joomla to WordPress and am trying to set up redirects for the various pages to their new URLs. The Joomla installation was set to add a .html extension, so there are pages that are indexed with and without .html

There's also some URLs that have 9-uncategorised added to them so that I get a situation like:

/calcium/calcium-rich-foods
/calcium/calcium-rich-foods.html
/calcium/calcium-rich-foods/9-uncategorised
/calcium/calcium-rich-foods/9-uncategorised.html

All of which should be redirected to the new URL:

/ingredients/calcium/calcium-rich-foods/

I'm not sure what the best way of setting this up is. I've tried:

RedirectMatch 301 /calcium/calcium-rich-foods http://example.com/ingredients/calcium/calcium-rich-foods/

And that works for the 4 example links above, but I guess I have to then add individual Redirect 301 rules for

/calcium
/calcium.html

as setting up a RedirectMatch for those causes any of the child pages of /calcium to redirect to the parent page, regardless of which order the redirects are listed.

Any suggestions would be appreciated.

Thanks.

2 Replies to “How to redirect pages that have multiple URL …”

Jeff Starr
Posted by Jeff Starr

Hi Kevin,

So just to understand correctly, the following URLs:

/calcium
/calcium.html
/calcium/calcium-rich-foods
/calcium/calcium-rich-foods.html
/calcium/calcium-rich-foods/9-uncategorised
/calcium/calcium-rich-foods/9-uncategorised.html

..all need redirected to this:

http://example.com/ingredients/calcium/calcium-rich-foods/

If so, then something like this would work:

RedirectMatch 301 /calcium http://example.com/ingredients/calcium/calcium-rich-foods/

If not, you could set up a separate redirect for /calcium and /calcium.html

Posted by Kevin Meronuk •

Thanks for the reply.

Wasn't able to set it up that way, as /calcium was and still needed to be a separate page from /calcium/calcium-rich-foods.

I just ended up not creating redirects for the parent pages/categories without the .html extension.