<p>This is not something built into Craft, but you could accomplish this with a plugin. You could have it run during your plugin's init function. On each page load, it would take the current page and load it into a <code>currentUrl</code> session variable. Then when you went to another page, the previous page url would move from <code>currentUrl</code> to a <code>prevUrl</code> session variable, and the current one would go into <code>currentUrl</code>.</p>

<p>You would write a template variable to check and output them in your templates. You could possibly work with Craft's session flashes, but you would have to remember to tell it not to delete them when you grabbed them.</p>

CC BY-SA 3.0
2014-06-30T20:37:03.317Z
2014-06-30T20:37:03.317Z
Bryan Redeagle
<p>I'd guess if this existed it would be available through craft.session. Unfortunately, I don't see any reference to a variable for the previous page's URL in the documentation for craft.session:   </p>

<p><strong><a href="http://buildwithcraft.com/docs/templating/craft.session" rel="nofollow">http://buildwithcraft.com/docs/templating/craft.session</a></strong> </p>

CC BY-SA 3.0
2014-06-30T20:34:02.493Z
2014-06-30T20:34:02.493Z
Anna_MediaGirl
<p>Was looking for an answer and came up with an noob alternative.</p>

<p>On the paginated page (simplified):</p>

<pre><code>&lt;a href="{{entry.url}}/p{{pageInfo.currentPage}}"&gt;{{entry.title}}&gt;&lt;/a&gt;
</code></pre>

<p>This will parse the page segment as the last segment of the entry. I first tried to use getSegment, but page numbers are seen as pagination url's and therefore ignored as segments. So, on the entry page if it's a paginated section for instance:</p>

<pre><code>&lt;a href="/{{entry.section.handle}}/p{{craft.request.getPageNum()}}"&gt;back&lt;/a&gt;
</code></pre>

CC BY-SA 3.0
2018-02-12T10:06:26.020Z
2018-02-12T10:06:26.020Z
noregt
<p>The easiest way would be to check <a href="http://buildwithcraft.com/docs/templating/craft.request#urlReferrer">craft.request.urlReferrer</a> and see if they just came from the entry index page. If so, provide a link to send them back.</p>

<pre><code>{% set referrer = craft.request.urlReferrer %}
{% set indexBaseUrl = url('articles') %}

{% if referrer and referrer|slice(0, indexBaseUrl|length) == indexBaseUrl %}
    &lt;a href="{{ referrer }}"&gt;Go back&lt;/a&gt;
{% endif %}
</code></pre>

<p>Another, more explicit way to do it would be to actually pass the current page in the query string of the entry URLs, from the entry index page.</p>

<pre><code>{% for entry in entries %}
    {% set url = url(entry.uri, { page: craft.request.pageNum }) %}
    &lt;a href="{{ url }}"&gt;{{ entry.title }}&lt;/a&gt;
{% endfor %}
</code></pre>

<p>Then you could check for that “page” query string param in the single entry template:</p>

<pre><code>{% set indexPage = craft.request.getQuery('page') %}
{% if indexPage %}
    {% set indexUrl = url('articles/' ~ craft.config.pageTrigger ~ indexPage) %}
    &lt;a href="{{ indexUrl }}"&gt;Go back&lt;/a&gt;
{% endif %}
</code></pre>

CC BY-SA 3.0
2014-06-30T22:00:55.303Z
2014-06-30T22:00:55.303Z
Brandon Kelly
<p>While I know the back button does this perfectly well, I was wondering if there was a good way to "return to" a paginated page using a previous request or something? Wanting to do this server-side rather than relying on JS. Thanks.</p>

CC BY-SA 3.0
2014-06-30T20:28:20.803Z
Can you elaborate a bit? E.g. are you linking from a paginated entry listing to an entry's actual URL?
Brandon Kelly
CC BY-SA 3.0
2014-06-30T20:47:21.423Z
Precisely. A blog list view that is paginated. Say you're on pg 5 and choose an entry I want to go back to pg 5 with a text link on entry view versus just the blog landing page. Wasn't sure if it was in the request or session arrays or not. If not, I will make a small plugin.
Ryan Shrum
<pagination>
Back to paginated page
# Back to paginated page

(Asked by: username_0 on 2014-06-30)

While I know the back button does this perfectly well, I was wondering if there was a good way to "return to" a paginated page using a previous request or something? Wanting to do this server-side rather than relying on JS. Thanks.

**Tags:** pagination
> **Comments:**
> **username_1**: Can you elaborate a bit? E.g. are you linking from a paginated entry listing to an entry's actual URL?  
> **username_0**: Precisely. A blog list view that is paginated. Say you're on pg 5 and choose an entry I want to go back to pg 5 with a text link on entry view versus just the blog landing page. Wasn't sure if it was in the request or session arrays or not. If not, I will make a small plugin.  

---

## 4 answers

### Answer by username_1 on 2014-06-30. Score: 6 | Accepted answer

The easiest way would be to check craft.request.urlReferrer and see if they just came from the entry index page. If so, provide a link to send them back.
{% set referrer = craft.request.urlReferrer %}
{% set indexBaseUrl = url('articles') %}

{% if referrer and referrer|slice(0, indexBaseUrl|length) == indexBaseUrl %}
    Go back
{% endif %}

Another, more explicit way to do it would be to actually pass the current page in the query string of the entry URLs, from the entry index page.
{% for entry in entries %}
    {% set url = url(entry.uri, { page: craft.request.pageNum }) %}
    {{ entry.title }}
{% endfor %}

Then you could check for that “page” query string param in the single entry template:
{% set indexPage = craft.request.getQuery('page') %}
{% if indexPage %}
    {% set indexUrl = url('articles/' ~ craft.config.pageTrigger ~ indexPage) %}
    Go back
{% endif %}


---

### Answer by username_2 on 2014-06-30. Score: 4

This is not something built into Craft, but you could accomplish this with a plugin. You could have it run during your plugin's init function. On each page load, it would take the current page and load it into a `currentUrl` session variable. Then when you went to another page, the previous page url would move from `currentUrl` to a `prevUrl` session variable, and the current one would go into `currentUrl`.

You would write a template variable to check and output them in your templates. You could possibly work with Craft's session flashes, but you would have to remember to tell it not to delete them when you grabbed them.


---

### Answer by username_3 on 2014-06-30. Score: 2

I'd guess if this existed it would be available through craft.session. Unfortunately, I don't see any reference to a variable for the previous page's URL in the documentation for craft.session:

**<http://buildwithcraft.com/docs/templating/craft.session>**


---

### Answer by username_4 on 2018-02-12. Score: 1

Was looking for an answer and came up with an noob alternative.
On the paginated page (simplified):
{{entry.title}}>

This will parse the page segment as the last segment of the entry. I first tried to use getSegment, but page numbers are seen as pagination url's and therefore ignored as segments. So, on the entry page if it's a paginated section for instance:
back


---

