1
我有一個嚴重的問題與我的WP網站之一。 Plaese看看我的重寫規則:WP:如何add_rewrite_rule()不創建額外的頁面
function set_rewrite_rules(){
add_rewrite_tag('%posttype%', '([^&]+)');
add_rewrite_rule('^expertise[/]([^/]+)[/]([^/]+)[/]page[/]([0-9]+)[/]?',
'index.php?expertise=$matches[1]&posttype=$matches[2]&paged=$matches[3]',
'top');
add_rewrite_rule('^expertise[/]([^/]*)[/]articles[/]([^/]+)[/]?',
'index.php?article=$matches[2]',
'top');
add_rewrite_rule('^expertise[/]([^/]*)[/]verdicts[/]([^/]+)[/]?',
'index.php?verdict=$matches[2]',
'top');
add_rewrite_rule('^expertise[/]([^/]*)[/]laws[/]([^/]+)[/]?',
'index.php?law=$matches[2]',
'top');
add_rewrite_rule('^expertise[/]([^/]*)[/]prosecutions[/]([^/]+)[/]?',
'index.php?prosecution=$matches[2]',
'top');
add_rewrite_rule('^expertise[/]([^/]+)[/]([^/]+)[/]?',
'index.php?expertise=$matches[1]&posttype=$matches[2]',
'top');
}
add_action('init', 'set_rewrite_rules');
它的偉大工程,但外幣很多額外的頁面,如:
/expertise/[EX-NAME]/page/2/page/4/page/3/page/2/page/4/page/2/
通常應返回404,但現在這些網頁作品&看起來像一個正常的有效頁面。 預期結果:分頁只能與一次匹配一起使用。例如:
/expertise/[EX-NAME]/page/2/
一切正常,而set_rewrite_rules
被註釋掉。
嘗試在第一個重寫規則結束時添加一個'$',看看會發生什麼。 – revo
@revo試過了。 [/]([^ /] +)[/]([^ /] +)[/]頁面[/]([0-9] +)[/] ?'','index.php?expertise = $ matches [1]&posttype = $ matches [2]&paged = $ matches [3]','top');' –
如果您刪除了這個特定的重寫規則? – revo