wordpress URL end with a number

后端 未结 1 1431
执念已碎
执念已碎 2021-01-03 03:19

I am not sure if this is a known issue or suppose to be like this performance,

any wordpress website, if you put a number at the end of the URL, for example,

<
1条回答
  •  天命终不由人
    2021-01-03 04:20

    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
    

    Posts can be paginated with . WordPress displays the content of the last page if no further content is found (or the full post if the post is not paginated).

    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, '' ) + 1;
            if( $page > $num_pages ){
                include( get_template_directory() . '/404.php' );
                exit;
            }
        }
    }
    

    0 讨论(0)
提交回复
热议问题