最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

rewrite rules - add_rewrite_rule redirects if value = 1

programmeradmin3浏览0评论

I'm currently having a small issue with add_rewrite_rule and can't seem to find any similar issues on stack overflow (even though there seems to be a lot).

It works fine for every URL I try:

profile/0/

profile/2/

profile/12313131/

I'm able to get the variable easy enough using $wp_query->query_vars['pid']

But if I try:

profile/1/

it always redirects to profile/

This is the only value that won't work. I can work around this if need be but wondering why this is the case? This is the first time I've had to use add_rewrite_rule and I normally just use htaccess.

Any help would be greatly appreciated.

The code I'm using is:

function profile_rewrite() {

    add_rewrite_tag('%pid%', '([0-9]+)');
    add_rewrite_rule('^profile/([0-9]+)/?', 'profile/?pid=$1', 'top');

}
add_action( 'init', 'profile_rewrite', 10, 0 );
发布评论

评论列表(0)

  1. 暂无评论