<p>As far as I understand it, the <code>postLoginRedirect</code> only affects login forms defined on the the front-end. If a user visits the login page (through a 'login' link for example), then they will be redirected to 'postLoginRedirect' after logging in. They will also be redirected there if they attempt to visit the login form directly when already logged in.</p>

<p>Your best option is to just create a quick login page template, like <a href="http://buildwithcraft.com/docs/templating/login-form" rel="nofollow">the one provided in the docs</a>. Craft will automatically look for 'login.html' in your templates folder - otherwise you can specify the location using the <a href="http://buildwithcraft.com/docs/config-settings#loginPath" rel="nofollow">loginPath</a> config setting.</p>

<p>With that defined, if a user tries to visit any page that has {{ loginRequired }} specified, they will automatically get redirected to the login page and subsequently be redirected back to the original page request after login.</p>

CC BY-SA 3.0
2015-02-11T15:36:38.197Z
2015-02-11T15:36:38.197Z
Douglas McDonald
<p>I have created an entry that requires users to be logged into to see it. This was just a minor request from our client and we didn't want to spend a lot of time setting up login forms etc.</p>

<p>Therefore I have just added <code>{% requireLogin %}</code> to the top of the entry's Twig file. This works great, so far so good.</p>

<p>The problem comes however when a user visits the URL for that page:</p>

<pre><code>www.foo.com/lorem
</code></pre>

<p>They are re-directed to the Craft login, as expected, but once they successfully login, instead of being re-directed back to the page, they are instead taken to the Craft admin dashboard, with the pages' slug at the end. So:</p>

<pre><code>www.foo.com/admin/lorem
</code></pre>

<p>Can anyone shed some light as to what is going on here? How can I make it so once users are loged in, they are re-directed back to the page? I've seen Craft has a <code>postLoginRedirect</code> <a href="http://buildwithcraft.com/docs/config-settings#postLoginRedirect" rel="nofollow">config</a>, but I'm guessing this can't be set on a per-page basis.</p>

CC BY-SA 3.0
2015-02-11T13:52:29.893Z
Have you tried this with a non CP account? I believe any account with CP access automatically gets redirected to the control panel, so this would only work for user accounts that don't have that level of access.
Peter Tell
CC BY-SA 3.0
2015-02-11T13:55:35.050Z
@PeterTell Thanks Peter, but unfortunately that would not work in this instance. Our client has CP access so they can make content changes, but they want to be the only people who want to see this page.
Jamie Wade
<redirect><login>
Re-directing to front-end after login
# Re-directing to front-end after login

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

I have created an entry that requires users to be logged into to see it. This was just a minor request from our client and we didn't want to spend a lot of time setting up login forms etc.
Therefore I have just added {% requireLogin %} to the top of the entry's Twig file. This works great, so far so good.
The problem comes however when a user visits the URL for that page:
www.foo.com/lorem

They are re-directed to the Craft login, as expected, but once they successfully login, instead of being re-directed back to the page, they are instead taken to the Craft admin dashboard, with the pages' slug at the end. So:
www.foo.com/admin/lorem

Can anyone shed some light as to what is going on here? How can I make it so once users are loged in, they are re-directed back to the page? I've seen Craft has a postLoginRedirect config, but I'm guessing this can't be set on a per-page basis.

**Tags:** redirect, login
> **Comments:**
> **username_1**: Have you tried this with a non CP account? I believe any account with CP access automatically gets redirected to the control panel, so this would only work for user accounts that don't have that level of access.  
> **username_0**: @PeterTell Thanks Peter, but unfortunately that would not work in this instance. Our client has CP access so they can make content changes, but they want to be the only people who want to see this page.  

---

## 1 answers

### Answer by username_2 on 2015-02-11. Score: 2

As far as I understand it, the `postLoginRedirect` only affects login forms defined on the the front-end. If a user visits the login page (through a 'login' link for example), then they will be redirected to 'postLoginRedirect' after logging in. They will also be redirected there if they attempt to visit the login form directly when already logged in.

Your best option is to just create a quick login page template, like [the one provided in the docs](http://buildwithcraft.com/docs/templating/login-form). Craft will automatically look for 'login.html' in your templates folder - otherwise you can specify the location using the [loginPath](http://buildwithcraft.com/docs/config-settings#loginPath) config setting.

With that defined, if a user tries to visit any page that has {{ loginRequired }} specified, they will automatically get redirected to the login page and subsequently be redirected back to the original page request after login.


---

