用一个参数在WordPress中重写URL

时间:2019-01-24 19:25:40

标签: php wordpress .htaccess url-rewriting

我有一个名为“城市”的页面:

http://localhost/wordpress/city/

它通过URL id从MySQL获取详细信息,

http://localhost/wordpress/city/?id=paris

我想要更改它,例如:

http://localhost/wordpress/city/paris

WordPress中城市页面的真正链接是:

http://localhost/wordpress/index.php?p=5

我尝试了add_rewrite_rule,但是不起作用:

add_action( 'init', 'add_mypage_rule' );
function add_mypage_rule() {
    add_rewrite_tag("%id%", '(\d+)');
    add_rewrite_rule('^city/([^/]*)/?','index.php?p=5&id=$matches[1]','top');
}

add RewriteRule应该使用什么.htaccess

0 个答案:

没有答案