How to retrieve $_GET variables from rewritten URLs?

To be added on init:

To register your custom variable (‘id’ in the question)

add_rewrite_tag('%mycustomvar%','([^&]+)');

To create a re-write rule:

add_rewrite_rule('^product/([0-9]{1,})/?','index.php?p=4&mycustomvar=$matches[1]','top')

4 is the id of the ‘product’ page. You will need to flush rewrite rules once after adding these (go to Permalink settings page)

You can get the value of mycustomvar: get_query_var( 'mycustomvar' ).

See Codex for:

Leave a Comment