[英]Custom Rewrite Rule in Wordpress
I am trying to create a custom page in Wordpress with a special URL Rewrite and I am trying the following: 我正在尝试使用特殊的URL重写在Wordpress中创建自定义页面,并且正在尝试以下操作:
function custom_rewrite_rule() {
add_rewrite_rule('^services/service-in-([^/]*)/?','index.php?page_id=238&location=$matches[1]','top');
}
add_action('init', 'custom_rewrite_rule');
However, when I go to domain.com/services/service-in-london/ I just get a 404 message. 但是,当我转到domain.com/services/service-in-london/时,我只会收到404消息。
I have also tried this manually in htaccess but just get a 404. 我也曾在htaccess中手动尝试过此操作,但只得到了404。
Can you please try below code 你能试试下面的代码吗
function custom_rewrite_rule() {
add_rewrite_tag('%location%', '([^/]*)');
add_rewrite_rule('^services/([^/]*)/?$', 'index.php?page_id=238&location=$matches[1]', 'top');
flush_rewrite_rules();
}
add_action('init', 'custom_rewrite_rule');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.