How to rewrite category URL?

I have two category page layouts. Which layout is shown is controlled by an intro var in the URL. Here’s the normal category view/url:

mysite.com/my-taxonomy/my-cat-slug/

and here’s the “intro” category view/url:

mysite.com/my-taxonomy/my-cat-slug/?intro=1

That is all working properly. But now I need to rewrite the second URL format to get rid of the intro=1. I want to rewrite it to:

mysite.com/my-taxonomy-intro/my-cat-slug/

I tried this:

add_rewrite_rule(
‘^my-taxonomy-intro/([a-z-]+)/?’,
‘my-taxonomy/$matches[1]/?intro=1’,
‘top’);

but when I test it I just get a 404. However, if I use this test:

add_rewrite_rule(
‘^my-taxonomy-intro/([a-z-]+)/?’,
‘index.php?page_id=2’,
‘top’);

then it works properly and redirects to that page with id=2.

Is there a way to pass the category slug and the intro=1 to index.php?

Read more here:: How to rewrite category URL?

Leave a Reply

Your email address will not be published. Required fields are marked *