wordpress URL 以数字结尾 [英] wordpress URL end with a number
问题描述
我不确定这是已知问题还是假设与此性能类似,
I am not sure if this is a known issue or suppose to be like this performance,
任何 wordpress 网站,如果您在 URL 末尾放置一个数字,例如,
any wordpress website, if you put a number at the end of the URL, for example,
http://perishablepress.com/wordpress-multisite-mamp/
我们把 1 或任何数字放在最后
we put 1 or any numbers at the end
http://perishablepress.com/wordpress-multisite-mamp/123
我们不会得到 NOT FOUND
页面,我们仍会停留在同一页面,即
We will not get the NOT FOUND
page, we'll still stay at the same page, which is
http://perishablepress.com/wordpress-multisite-mamp/
这是错误还是正常?我们如何重定向到 NOT FOUND PAGE?
Is this an error or normal ? how do we redirect to NOT FOUND PAGE instead?
推荐答案
这不是错误,123
被解释为分页参数:
It's not an error, the 123
is interpreted as a pagination parameter:
Request: wordpress-multisite-mamp/123
Query String: page=%2F123&name=wordpress-multisite-mamp
Matched Rewrite Rule: ([^/]+)(/[0-9]+)?/?$
Matched Rewrite Query: name=wordpress-multisite-mamp&page=%2F123
文章可以使用 进行分页.如果没有找到更多内容,WordPress 会显示最后一页的内容(如果帖子没有分页,则显示完整帖子).
Posts can be paginated with <!--nextpage-->
. WordPress displays the content of the last page if no further content is found (or the full post if the post is not paginated).
要在分页参数超过页数时重定向到 404 页面,请将以下内容放入您的 functions.php
文件中:
To redirect to the 404 page when the pagination parameter exeeds the number of pages, drop the following in your functions.php
file:
add_action( 'template_redirect', 'so16179138_template_redirect', 0 );
function so16179138_template_redirect()
{
if( is_singular() )
{
global $post, $page;
$num_pages = substr_count( $post->post_content, '<!--nextpage-->' ) + 1;
if( $page > $num_pages ){
include( get_template_directory() . '/404.php' );
exit;
}
}
}
这篇关于wordpress URL 以数字结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!