使 WordPress 以两种不同的 url 模式显示同一页面
Make WordPress show the same page on two different url patterns
我需要让 WordPress 在两个不同的 URL 上显示相同的页面:
https://sitename.com/%postname%/
https://sitename.com/%postname%/tail/
* 我只能用functions.php
我使用了一些类似的案例和指南,下面是对我有用的代码:
function tail_rewrite()
{
add_rewrite_rule('^([^/]*)/tail?', 'index.php?name=$matches[1]', 'top');
// first parameter for posts: p or name, for pages: page_id or pagename
}
add_action('init', 'tail_rewrite');
don't forget to flush the rules by visiting Settings > Permalinks
OR use flush_rewrite_rules() in the plugin activation (don't execute it at every page load).
我需要让 WordPress 在两个不同的 URL 上显示相同的页面:
https://sitename.com/%postname%/
https://sitename.com/%postname%/tail/
* 我只能用functions.php
我使用了一些类似的案例和指南,下面是对我有用的代码:
function tail_rewrite()
{
add_rewrite_rule('^([^/]*)/tail?', 'index.php?name=$matches[1]', 'top');
// first parameter for posts: p or name, for pages: page_id or pagename
}
add_action('init', 'tail_rewrite');
don't forget to flush the rules by visiting Settings > Permalinks OR use flush_rewrite_rules() in the plugin activation (don't execute it at every page load).