Wordpress添加重写URL看起来像WPML

时间:2014-11-17 06:36:24

标签: wordpress rewrite

与标题相同,我想访问链接:

mysite.domain/hello-word
mysite.domain/my_slug/hello-word

是相同的链接,看起来像WPML:

mysite.domain/hello-word
mysite.domain/en/hello-word

我试试:

function custom_rewrite_tag() {
    add_rewrite_rule('^([^/]*)/?/([^/]*)/?', 'index.phptheme_var=$matches[0]&pagename=$matches[1]', 'top');
    add_rewrite_tag('%theme_var%', '([^&]+)');
}

add_action('init', 'custom_rewrite_tag', 10, 0);

但没有工作,有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

你忘了问号吗?

add_rewrite_rule('^([^/]*)/?/([^/]*)/?', 'index.php?theme_var=$matches[0]&pagename=$matches[1]', 'top');

在index.php和theme_var之间