bodk9800
bodk9800

Reputation: 23

Too many redirects regex redirect

I am on Wordpress and right now using Yoast Seo Pro which has a redirection section including a Regular Expressions redirects section.

How do I redirect say /mycategory1/page/pagenumberhere/ to /category/mycategory1/page/pagenumberhere/ ?

So I only need to make one redirect that handles all possible page numbers?

I have tried /mycategory1/page/([0-9]) to /category/mycategory1/page/$1
It looks like it redirects to /category/mycategory1/page/pagenumberhere/ but there is an err_too_many_redirects on the /category/mycategory1/page/pagenumberhere/ with this rule added so I have removed it again.

If you can help with code into the .htaccess instead perhaps I could try that.

Upvotes: 1

Views: 345

Answers (1)

Olaf Dietsche
Olaf Dietsche

Reputation: 74078

Your rule already looks promising.

However, as @starkeen pointed out, the regular expression mycategory1/page/([0-9]) matches every request containing mycategory1/page/ with some trailing number. This is true of category/mycategory1/page/ as well, as it also contains "mycategory1/page".

If you want to match requests starting with mycategory1/page, you must anchor the regular expression at the beginning with ^, see Apache mod_rewrite Introduction - Regex vocabulary

RewriteRule ^mycategory1/page/([0-9]) /category/mycategory1/page/$1 [L]

Upvotes: 1

Related Questions