I’m trying to clean the URL in wordpress.
instead of this www.website.com/mypage/?myvariable=fr
I want to have this www.website.com/fr/mypage/
The redirection works well, but I can not get the value I put in the URL as a $_GET value.
In the first part I used add_rewrite_rule seems to work well. The redirection is OK.
function add_rewrite(){
flush_rewrite_rules();
add_rewrite_rule(
'fr/([a-z0-9-]+)',
'index.php?pagename=$matches[1]&myvariable=fr',
'top'
);
}
add_action('init', 'add_rewrite');
But I can not get the value of myvariable wich looks empty
echo get_query_var("myvariable");
even if I use the folowing code
function add_query_vars($aVars) {
$aVars[] = "myvariable";
return $aVars;
}
add_filter('query_vars', 'add_query_vars');
New contributor
patrice pellier is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.