我创建了一个wordpress插件,它使用短代码和URL参数来加载某个文本。
默认页面为:
domainname.com/test
[shortcode for plugin]
... default template ...
它可以使用以下参数加载一些文本:
domainname.com/test?book_id=BWBR0002656&art_id=1
[shortcode for plugin]
... loaded the text for the book_id and art_id ...
我想将javascript参数网址从当前 domainname.com/test?book_id=BWBR0002656&art_id=1 更改为 domainname.com/test/BWBR0002656/ 1 ,但未触发wordpress 404重定向。
这可能与短代码页仍然有效吗?
答案 0 :(得分:1)
我设法使用它来实现:
add_action( 'init', 'wpa5413_init' );
function wpa5413_init()
{
// Remember to flush the rules once manually after you added this code!
add_rewrite_rule(
// The regex to match the incoming URL
'test/([^/]+)',
// The resulting internal URL: `index.php` because we still use WordPress
// `pagename` because we use this WordPress page
'index.php?pagename=test',
// This is a rather specific URL, so we add it to the top of the list
// Otherwise, the "catch-all" rules at the bottom (for pages and attachments) will "win"
'top' );
}
它将使用args加载/ test / page,javascript将处理其余部分。
接受/ test /之后的所有内容都没有404错误。甚至:/ test / a / b / c / d / e