url rewriting – Rewrite parameters as Url for SEO

Question

I have urls of this form:

example.com/event/?eventId=1
example.com/event/?eventId=2

The problem is Google is indexing only example.com/event, which is a blank page. It’s not able to display an event without the Id. I would like to rewrite this url to this form:

example.com/event/1

This will allow Google to index each event individually.

I imagine something like:

function add_eventId_rule() {
  add_rewrite_rule(
    '^event/(\d*)/?',
    'index.php?pagename=event&eventId=$matches[1]',
    'top'
  );
}

add_action( 'init', 'add_eventId_rule');

http://example.com/?pagename=event&eventId=1051 takes me to the right page.
example.com/event/1 strips the Id and takes me here: example.com/event

How come? What am I missing?

0
AldenG 4 months 2022-04-21T17:49:29-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse