我找到了一个不使用htaccess但使用WP函数WP\\u redirect的解决方案。复制和通过功能。php
function redirect_paginated_404() {
if (is_404()) {
$url = $_SERVER[\'REQUEST_URI\']; //read the url
$search = \'/page/\'; //chose the word of the url
if ( strpos( $url, $search ) !== false ) { //if i find the string /page/
//search the string /page/ in the url and delete everything after it, so the incorrectly page number
$short = substr($url, 0, strpos( $url, $search));
wp_redirect( $short, \'301\' ); // redirection function with the first page of category
exit;
}
}
}
add_action(\'template_redirect\', \'redirect_paginated_404\');
事实上,我不知道是否会破坏搜索引擎优化,但重定向工作正常。你觉得怎么样?是留下404错误更好,还是我可以使用类似的东西?
source