I have create a new rewrite rule for my wordpress website by putting the following code in functions.php

// Register a new var
function rc_add_query_vars( $vars) {
$vars[] = “referrer”; // name of the var as seen in the URL
return $vars;
}

// Hook our function into query_vars
add_filter(‘query_vars’, ‘rc_add_query_vars’);

// Add the new rewrite rule to existings ones
function rc_add_rewrite_rules($rules) {
$new_rules = array(‘^referrer/([^/|’.$pagename.’]+)/([^/]+)/?$’ => ‘/index.php? pagename=$matches[1]&referrer=$matches[2]’);
$rules = $new_rules + $rules;
return $rules;
}

// Hook the function into rewrite_rules_array
add_filter(‘rewrite_rules_array’, ‘rc_add_rewrite_rules’);

It works well, but the problem is that, it also changes the URL in browser address bar.
When I type the URL http://myexp.uphero.com/referrer/sample-page/
it redirects well, without any issue but it changes the URL to:

http://myexp.uphero.com/sample-page/

It should not change the URL, the URL should remain as same as I type in address bar.
Please help me to solve this issue.

Read more here: WordPress WP Rewrite Rules for Page redirects but changes the URL in browser


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: