WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I rewrite URLs on WordPress?

For example, I have a URL like sitename.com/?page=<numbers>&id=<numbers> and I want to rewrite it as sitename.com/page/id/<other info>. How can I do that? I don't understand the rules!

share|improve this question
up vote 0 down vote accepted

Your best bet for an easy solution is to actually use the "Custom Structure" option in your WordPress admin under Settings > Permalinks.

There are a number of other structure tags you may use as seen in the Codex.

If you're looking for even more customization and manual control, it's actually a pretty complex topic involving editing your .htaccess file. This great two part tutorial by Stephan Harris covers this topic very well. (Better than I ever could here on SO).

share|improve this answer
So, the rule might be (in my problem) add_rewrite_rule('^([0-9]*)/^([0-9]*)','index.php?page=$matches[1]&id=$matches[‌​2]','top'). Isn't it? – apanzett Jun 1 '13 at 15:20
@apanzett Well, the expression you have there will try to match numerics for the "page" portion. You might try something like add_rewrite_rule('^([^/]*)/^([0-9]*)','index.php?page=$matches[1]&id=$matches[‌‌​​2]','top'). Notice the slight difference is that the first section will match all strings (since page names are typically words and/or numbers). I've found Debuggex to be a pretty helpful tool for playing with regex. – Jared Cobb Jun 1 '13 at 16:23
And if I have a known page, i'll try something like ^PAGENAME/([0-9]*)/([^/]*)/([0-9]*) => index.php?page_id=$matches[1]&event=$matches[2]&id=$matches[3] where page_id and id are only numbers and event is string composed? – apanzett Jun 2 '13 at 14:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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