最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

rewrite rules - add_rewrite_rule redirects if value = 1

matteradmin8PV0评论

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 );
Post a comment

comment list (0)

  1. No comments so far