How to remove WordPress category from URL and have a custom pagination parameter/rewrite?

I’m trying to remove the Category URI from the WordPress URL and have a custom pagination rewrite. I’ll explain exactly what’s happening below:

So I have a blog.

We have two (main) categories: “bar-talk” and “tutorials”. I’ll use “Bar Talk” for the example.

I’ve found with WordPress, I can actually visit both of these URLs without doing anything custom:

- Current: https://scotch.io/category/bar-talk
- Want: https://scotch.io/bar-talk

However, the pagination that is automatically created breaks:

- Current: https://scotch.io/category/bar-talk/page/2 (works)
- Want: https://scotch.io/bar-talk/page/2 (doesn't work)

This makes sense as we haven’t done any custom rewrite yet. How do I get the second structure though? Then, following this, I’d like to do a rewrite on “page” so that we can do:

- Super want: https://scotch.io/bar-talk/drink-number/2

Some additional notes:

  • We’ve successfully previously done a rewrite to have “https://scotch.io/category/bar-talk/drink-number/2” work. But we really don’t want that category param as part of pagination anymore
  • Anything with tags works fine: “https://scotch.io/tag/javascript/drink-number/2”
  • Current permalink structure is “/%category%/%postname%”

Thanks!

3 Answers
3

Hm. Have you thought about doing some URL rewrites in .htaccess?

RewriteRule ^category/bar-talk/page/([0-9]+)$ /bar-talk/drink-number/$1 [L,R=301]
RewriteRule ^bar-talk/drink-number/([0-9]+)$ /index.php?category_name=bar-talk&page=$1 [L]

// @drizzlyowl

Leave a Comment