[英]WordPress URL Rewrite Rules
I have this URL: 我有这个网址:
example.com/products-and-services/?catID=5
I want to make it like this: 我想要这样:
example.com/products-and-services/5
Basically I am removing ?catID=
基本上我要删除?catID=
Here is my code with add_rewrite_rule
which I have no luck so far: 这是我的add_rewrite_rule
代码, add_rewrite_rule
我还没有运气:
function custom_rewrite_products() {
add_rewrite_rule('products-and-services/([^/]+)/?$',
'index.php?pagename=products-and-services&catID=$matches[1]', 'top');
}
add_action('init', 'custom_rewrite_products')
Any suggestions? 有什么建议么?
Give this a try: 试试看:
function custom_rewrite_products() {
add_rewrite_rule(
'^products-and-services/([^/]*)/?$',
'index.php?pagename=products-and-services&catID=$matches[1]',
'top'
);
}
add_action( 'init', 'custom_rewrite_products' );
More details here: https://wordpress.stackexchange.com/questions/250837/understanding-add-rewrite-rule 此处有更多详细信息: https : //wordpress.stackexchange.com/questions/250837/understanding-add-rewrite-rule
Use This. 用这个。
function custom_rewrite_tags() {
add_rewrite_tag('%catID%', '([^&]+)');
}
add_action('init', 'custom_rewrite_tags', 10, 0);
function custom_rewrite_products() {
add_rewrite_rule('^products-and-services/([\w+]*)/', 'index.php/?pagename=products-and-services&catID=$matches[1]', 'top');
}
add_action('init', 'custom_rewrite_products');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.