Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wordpress URL end with a number

Tags:

wordpress

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,

http://perishablepress.com/wordpress-multisite-mamp/

we put 1 or any numbers at the end

http://perishablepress.com/wordpress-multisite-mamp/123

We will not get the NOT FOUND page, we'll still stay at the same page, which is

http://perishablepress.com/wordpress-multisite-mamp/

Is this an error or normal ? how do we redirect to NOT FOUND PAGE instead?

like image 829
olo Avatar asked Apr 23 '13 21:04

olo


People also ask

How do I remove 20 from URL in WordPress?

Remove Numbers from URL Slug in WordPress Classic Editor Clicking on the edit button will make the URL editable. This editable part is called the post slug. You can enter the text you want to use as a post slug in the URL and remove numbers.

How do I add a slash to my WordPress URL?

To do so, go to the “Settings -> Permalinks” section and, depending on your situation, either add or delete the last slash. The “Custom Structure” field ends with a slash, so all other WordPress URLs will have the trailing slash. Likewise, if it is not present there, the slash will be missing in your website's URLs.


1 Answers

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 <!--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).

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;
        }
    }
}
like image 113
diggy Avatar answered Sep 18 '22 12:09

diggy