url rewriting - Wordpress Rewrite URL not working with rewrite_rules_array filter -
i have in functions.php (wp 4.6.x) rewrite long pretty urls shorter permalinks posts set $home/ ...
function kl_add_query_vars($avars) { $avars[] = "urlklcity"; $avars[] = "urlklarea"; $avars[] = "urlcatslug"; $avars[] = "urlcategory"; $avars[] = "urlphonenumber"; //echo "in kl_add_query_vars"; return $avars; } // hook add_query_vars function query_vars add_filter('query_vars', 'kl_add_query_vars'); function kl_add_rewrite_rules($arules) { // matches {home}/{1}/{2}/[3] , nothing else search urls //$anewrules = array('([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)? $'=>'/index.php?? page_id=13988&urlklcity=$matches[1]&urlklarea=$matches[2]&urlcatslug=$matches[3]', $anewrules = array('([^/]+)/([^/]+)/([^/]+)?$' => '/index.php?page_id=13988&urlklcity=$matches[1]&urlklarea=$matches[2]&urlcatslug=$matches[3]'); //echo 'found url pattern '.$matches[1].' - '.$matches[2]; $arules = $anewrules + $arules; // #oldrule //$anewrules = array('([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$' => '/index.php?page_id=13988&urlklcity=$matches[1]&urlklarea=$matches[2]&urlcatslug=$matches[3]'); // #newrule $anewrules = array('([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$' => '/index.php?pagename=$matches[5]'); $arules = $anewrules + $arules; return $arules; } // hook add_rewrite_rules function rewrite_rules_array add_filter('rewrite_rules_array', 'kl_add_rewrite_rules');
interestingly, oldrule works , redirects intended page.
problem newrule gives 404
i have tested site works index.php?pagename=xxx manually
i hardcoded postname in newrule , works too!!
i have debugged using rewrite analyzer plugin shows should work.
any helpful pointers appreciated.
Comments
Post a Comment