I have two pages, one called cities and the other called states. They use the add_query_vars function to grab the city and or state from a database. The pages load fine. For example when someone goes to sitename.com/roller-derbies/arizona/florence/ and the events in that city display. But when I view the page source and look at the canonical link inserted in wp-head it says sitename.com/cities or sitename.com/states after the page name. This creates a problem where none of my pages are being indexed by google as they all point to canonical link for cities or states. What can I do so the canonical link matches the url?
Below is the code I am using.
add_filter('query_vars', 'add_query_vars');
function add_query_vars($aVars) {
$aVars[] .= 'var_state';
$aVars[] .= 'var_city';
return $aVars;
}
add_filter('rewrite_rules_array', 'add_rewrite_rules');
function add_rewrite_rules($aRules) {
$aNewRules = array(
'roller-derbies/([^/]+)/?$' => 'index.php?pagename=states&var_state=$matches[1]',
'roller-derbies/([^/]+)/([^/]+)/?$' => 'index.php?pagename=cities&var_state=$matches[1]&var_city=$matches[2]',
$aRules = $aNewRules + $aRules;
return $aRules;
}
