<p>You should create your /login template with a <a href="https://craftcms.com/docs/templating/login-form" rel="nofollow">custom login form</a>. If you do that, the redirect should work as expected:</p>

<blockquote>
  <p>craft.session.returnUrl is set to the original URL that included the {% requireLogin %} tag that initiated the redirect to this login form.</p>
</blockquote>

CC BY-SA 3.0
2016-02-11T11:59:39.280Z
2016-02-11T11:59:39.280Z
chris
<p>I'm trying to get the following behavior, but it's not working:</p>

<p>If a user goes to <a href="http://example.com/addresses" rel="nofollow">http://example.com/addresses</a> he should get redirected to the Craft login form. So the corresponding template has a <code>{% requireLogin %}</code> tag. After a successful login the user should be redirected to the page he was trying to access (in the case <a href="http://example.com/addresses" rel="nofollow">http://example.com/addresses</a>)</p>

<p>Without any additions to the config array the redirect goes to <a href="http://example.com/login" rel="nofollow">http://example.com/login</a> which is a 404 page.</p>

<p>If I add the loginPath setting to the config file and set it to 'admin/login' it redirects to the correct Craft login form, but after login it's not going to /addresses but /admin/addresses </p>

<p>What settings would lead to the desired behavior?</p>

<redirect><login>
requireLogin not redirecting to login page
# requireLogin not redirecting to login page

(Asked by: username_0 on 2016-02-11)

I'm trying to get the following behavior, but it's not working:

If a user goes to <http://example.com/addresses> he should get redirected to the Craft login form. So the corresponding template has a `{% requireLogin %}` tag. After a successful login the user should be redirected to the page he was trying to access (in the case <http://example.com/addresses>)

Without any additions to the config array the redirect goes to <http://example.com/login> which is a 404 page.

If I add the loginPath setting to the config file and set it to 'admin/login' it redirects to the correct Craft login form, but after login it's not going to /addresses but /admin/addresses

What settings would lead to the desired behavior?

**Tags:** redirect, login


---

## 1 answers

### Answer by username_1 on 2016-02-11. Score: 3 | Accepted answer

You should create your /login template with a [custom login form](https://craftcms.com/docs/templating/login-form). If you do that, the redirect should work as expected:

> craft.session.returnUrl is set to the original URL that included the {% requireLogin %} tag that initiated the redirect to this login form.


---

