<p>If you are using <code>{% requireLogin %}</code> tags, then the Craft UserSession service has a <code>getReturnUrl()</code> method which should give you what you want. It is accessible in your templates via <code>craft.session.returnUrl</code>. <a href="http://buildwithcraft.com/docs/templating/craft.session#getReturnUrl">Here is a link to the docs</a>. Hope this helps! </p>

CC BY-SA 4.0
2019-04-05T20:13:58.337Z
I'm trying to do this same thing with Craft 3 and not sure how exactly. I simply have a link (below) on a page outside of the CP admin but want to redirect users back to this page after they've logged in on the normal CP admin login page. So a way to temporarily override `craft.app.user.returnUrl` if they're coming from this external page to the main CP login form. 

```
<a href="{{ cpUrl() }}" class="font-bold text-blue underline">Click here to log in</a>
```
Brian Larson
CC BY-SA 4.0
2019-04-05T20:34:37.157Z
Ok so I came up on this solution which will work in my case. It would be cool to somehow pass a temporary returnUrl it with a link to the login form so the user understands what's going on. At any rate I added {% requireLogin %} to my external page's template and then just needed (in my case) to add 'loginPath' => 'cp-admin/login' to general.php as well. https://docs.craftcms.com/v3/dev/tags/requirelogin.html#app --- or doy I can just a put a login form on the page itself by tweaking this one. https://docs.craftcms.com/v3/dev/examples/login-form.html
Brian Larson
CC BY-SA 3.0
2015-11-19T21:18:50.993Z
2015-11-19T21:18:50.993Z
kcolls
<p>I have some pages that require login from the user. What I'd like is for the user to get redirected to the page that they wanted after they've logged in rather than sent to the page that they were on before they attempted to view a 'login required' page.</p>

<p>At present I have this in my login form:</p>

<pre><code>&lt;input type="hidden" name="redirect" value="{{ craft.request.getUrlReferrer }}"&gt;
</code></pre>

<p>Is there a craft request method I can use instead of getUrlReferrer to accomplish this?</p>

<login><request>
Redirect user to the page they wanted after login
# Redirect user to the page they wanted after login

(Asked by: username_0 on 2015-11-19)

I have some pages that require login from the user. What I'd like is for the user to get redirected to the page that they wanted after they've logged in rather than sent to the page that they were on before they attempted to view a 'login required' page.
At present I have this in my login form:


Is there a craft request method I can use instead of getUrlReferrer to accomplish this?

**Tags:** login, request


---

## 1 answers

### Answer by username_1 on 2015-11-19. Score: 6 | Accepted answer

If you are using `{% requireLogin %}` tags, then the Craft UserSession service has a `getReturnUrl()` method which should give you what you want. It is accessible in your templates via `craft.session.returnUrl`. [Here is a link to the docs](http://buildwithcraft.com/docs/templating/craft.session#getReturnUrl). Hope this helps!

> **Comments:**
> **username_2**: I'm trying to do this same thing with Craft 3 and not sure how exactly. I simply have a link (below) on a page outside of the CP admin but want to redirect users back to this page after they've logged in on the normal CP admin login page. So a way to temporarily override `craft.app.user.returnUrl` if they're coming from this external page to the main CP login form.   ``` <a href="{{ cpUrl() }}" class="font-bold text-blue underline">Click here to log in</a> ```  
> **username_2**: Ok so I came up on this solution which will work in my case. It would be cool to somehow pass a temporary returnUrl it with a link to the login form so the user understands what's going on. At any rate I added {% requireLogin %} to my external page's template and then just needed (in my case) to add 'loginPath' => 'cp-admin/login' to general.php as well. https://docs.craftcms.com/v3/dev/tags/requirelogin.html#app --- or doy I can just a put a login form on the page itself by tweaking this one. https://docs.craftcms.com/v3/dev/examples/login-form.html  

---

