Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress中的自定义重写规则_Wordpress - Fatal编程技术网

Wordpress中的自定义重写规则

Wordpress中的自定义重写规则,wordpress,Wordpress,我尝试在Wordpress中创建一个带有特殊URL重写的自定义页面,并尝试以下操作: 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'); 然而,当我进入domain.com

我尝试在Wordpress中创建一个带有特殊URL重写的自定义页面,并尝试以下操作:

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');
然而,当我进入domain.com/services/service-in-london/时,我只收到一条404消息


我也曾在htaccess中手动尝试过,但只得到了一个404。

你能试试下面的代码吗

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');