简体   繁体   中英

Rewrite custom url Wordpress

I've this url in Wordpress:

http://mywebsite.com/examples/detail/?id=6341

I want to change this like that:

http://mywebsite.com/examples/detail/id/6341

So I wrote this into functions.php

function custom_rewrite_basic() {
  add_rewrite_rule('^examples/detail/?id=([0-9]+)/?', 'index.php?id=$matches[1]', 'top');
}
add_action('init', 'custom_rewrite_basic');

But it does not work.

Try to update RegEx to catch what you want to see in URL and redirect accordingly:

function custom_rewrite_basic() {
  add_rewrite_rule('^examples/detail/id/([0-9]+)/?', 'index.php?id=$matches[1]', 'top');
}
add_action('init', 'custom_rewrite_basic');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM