I'm having an issue with me rewrite rule works fine here:


but when i use pagination to the next page i get a 404 here:


I was able to write two rewrite rules but now instead of getting a 404 page, the page refreshes with same content but URL changes here is my rewrite rules hopefully some one can help?

add_rewrite_rule( 'resources/([^/]+)/([^/]+)/?', 'index.php?taxonomy=res_category&term=$matches[1]&post_type=$matches[2]', 'top');
//added for page turn on pagination 
add_rewrite_rule('resources/([^/]+)/([^/]+)/page/([0-9]{1,})/?', 'index.php?taxonomy=res_category&term=$matches[1]&post_type=$matches[2]&paged=$matches[3]', 'top');  

thank you ahead for any help.

  • your rewrite rules appear to have an additional segment compared to your example URLs?
    – Milo
    Aug 14 '15 at 16:38
  • Looks like we both saw the same thing. I edited my response below with a fix. Aug 14 '15 at 17:05

At first blush, your code looks solid. Two suggestions:

1) Try putting the longer rewrite rule before the shorter one. It's possible that the first one is being matched (because it is a subset of the longer one) and then not proceeding to check the longer one.

2) Whenever you modify rewrite rules, you have to flush and reload the rewrite rules for them to take effect. The simplest way to do this is to go to Settings > Permalinks and click Save.

EDIT: Got it. Change your second rewrite rule to resources/([^/]+)/page/([0-9]{1,})/?. You had one too many wildcard segments.

  • I have switched their positions and no go. as well as reflush via Settings > Permalinks every time still nothing ...
    – HRone
    Aug 14 '15 at 16:10
  • Modified my answer above to include updated regex to use in your second call. The problem was that the paginated version includes one less URL segment than you were testing against, so the RegEx didn't match. Aug 14 '15 at 16:29
  • still nothing ... I switched positions and still... what it does is that it goes from example.com/resources/articles/ to here example.com//resources/articles/page/2/ in the URL but page does not change as well as the pagination ... just refreshes
    – HRone
    Aug 14 '15 at 17:25
  • You might be having a problem because the URL contains two slashes. Also, I usually add a ^ to the beginning of my add_rewrite_rule string so that it matches URLs that begin with that string. Can you try both of those suggestions and see if that helps? Aug 14 '15 at 18:27
  • Sorry, just noticed your answer above. Disregard. Aug 14 '15 at 18:28

I figured it out! I had too many parameters trying to match and had to replace "[^/]+" with "(.+?)" i was able to get this with just one rewrite rule here is the final code:

add_rewrite_rule( 'resources/(.+?)(/page/([0-9]+))?/?$', 'index.php?taxonomy=res_category&term=$matches[1]&paged=$matches[3]', 'top');

now the problem i have now i get a 404 on the post itself if i click on an article ??? any clue why??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.