Pagination returns a result after last page has been reached I understand I can use a conditional to output a 'next page' link only when next pages exist, but I am finding a problem with direct URLs. 

Let's say you have 20 entries and 10 per page. 

The URL /news (or /news/p1) and /news/p2 should work, but I would expect /news/p3 to show no results or a message.

What I'm finding however is that /news/p3 and beyond returns the last entry in the collection.

Here's the template code:

{% paginate craft.entries.section(listingSection).order('postDate desc').limit(2) as entriesOnPage %}

    &lt;div class="ral-loading ral-hero-block ral-headline"&gt;Loading the latest content...&lt;/div&gt;

    &lt;div class="isotope js-isotope" &gt;

        {% for entry in entriesOnPage %}

            {% if entry.section.handle != 'tweet' %}

                {% switch entry.tileSize %}

                    {% case "Single" %}

                        {% include '_partials/_isotope_block_single.html' %}

                    {% case "Double Horizontal" %}

                        {% include '_partials/_isotope_block_horizontal.html' %}

                    {% case "Double Vertical" %}

                        {% include '_partials/_isotope_block_vertical.html' %}

                    {% case "Quadruple" %}

                        {% include '_partials/_isotope_block_big.html' %}

                    {% case "Quote" %}

                        {% include '_partials/_isotope_block_quote.html' %}

                {% endswitch %}

            {% else %}

                {% include '_partials/_isotope_block_tweet.html' %}

            {% endif %}

        {% endfor %}

    &lt;/div&gt;

    {% if paginate.nextUrl %}

        &lt;div class="ral-load-more-posts nav-previous"&gt;

            &lt;div class="container"&gt;

                &lt;a class="ral-load-more-posts-text" href="{{ paginate.nextUrl }}"&gt;Load more posts&lt;/a&gt;

            &lt;/div&gt;

        &lt;/div&gt;

    {% endif %}

{% endpaginate %}
You can detect if the requested page is greater than the total available pages for the current list of entries like so:

{% paginate entries as entriesOnPage %}

    {% if craft.request.getPageNum() &gt; paginate.totalPages %}
        &lt;p&gt;No results&lt;/p&gt;
    {% else %}
        {% for entry in entriesOnPage %}
            ...
        {% endfor %}
    {% endif %}

{% endpaginate %}


Rather than displaying a message, you could also choose to put an {% exit 404 %} tag in there.