admin管理员组文章数量:1130349
I'm trying to get a rewrite_rules_array rule to work and running into issues. I would like to add a rule so that when someone visits:
It essentially loads:
What really happens is that Wordpress redirects you to .
add_filter('rewrite_rules_array', function( $rules ) {
$new = array();
$new['product/(.*)/(.*)/?'] = 'index.php?pagename=$matches[1]&view=$matches[2]';
return array_merge( $new, $rules );
});
- I've flushed my permalinks.
viewhas been added to the query_vars.
I'm trying to get a rewrite_rules_array rule to work and running into issues. I would like to add a rule so that when someone visits:
http://domain/product/foo/bar
It essentially loads:
http://domain/product/foo?view=bar
What really happens is that Wordpress redirects you to http://domain/product/foo.
add_filter('rewrite_rules_array', function( $rules ) {
$new = array();
$new['product/(.*)/(.*)/?'] = 'index.php?pagename=$matches[1]&view=$matches[2]';
return array_merge( $new, $rules );
});
- I've flushed my permalinks.
viewhas been added to the query_vars.
1 Answer
Reset to default 0For anyone looking, the solution was:
add_action('init', function() {
add_rewrite_rule(
'product/(.*)/(.*)/?',
'index.php?product=$matches[1]&view=$matches[2]',
'top'
);
});
I'm trying to get a rewrite_rules_array rule to work and running into issues. I would like to add a rule so that when someone visits:
It essentially loads:
What really happens is that Wordpress redirects you to .
add_filter('rewrite_rules_array', function( $rules ) {
$new = array();
$new['product/(.*)/(.*)/?'] = 'index.php?pagename=$matches[1]&view=$matches[2]';
return array_merge( $new, $rules );
});
- I've flushed my permalinks.
viewhas been added to the query_vars.
I'm trying to get a rewrite_rules_array rule to work and running into issues. I would like to add a rule so that when someone visits:
http://domain/product/foo/bar
It essentially loads:
http://domain/product/foo?view=bar
What really happens is that Wordpress redirects you to http://domain/product/foo.
add_filter('rewrite_rules_array', function( $rules ) {
$new = array();
$new['product/(.*)/(.*)/?'] = 'index.php?pagename=$matches[1]&view=$matches[2]';
return array_merge( $new, $rules );
});
- I've flushed my permalinks.
viewhas been added to the query_vars.
-
Your products are pages of the
pagepost type? Also- just useadd_rewrite_rulehooked toinitif you’re just adding rules and not manipulating existing rules or reordering. – Milo Commented Nov 14, 2018 at 23:00 - @Milo They are of type 'product'. – Louis W Commented Nov 15, 2018 at 2:19
1 Answer
Reset to default 0For anyone looking, the solution was:
add_action('init', function() {
add_rewrite_rule(
'product/(.*)/(.*)/?',
'index.php?product=$matches[1]&view=$matches[2]',
'top'
);
});
本文标签: url rewritingHelp adding custom urlrewriterulesarray
版权声明:本文标题:url rewriting - Help adding custom url, rewrite_rules_array 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749180842a2328579.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


pagepost type? Also- just useadd_rewrite_rulehooked toinitif you’re just adding rules and not manipulating existing rules or reordering. – Milo Commented Nov 14, 2018 at 23:00