<p>Yeah... that won't work.</p>

<p>Craft currently uses the URI segments to determine special path like logging in, out, etc.</p>

<p>So when Craft sees <code>account</code> as the first segment in the URI, its going to treat that as a login request and execute what's in <code>UsersController-&gt;actionLogin()</code>, which will see that you're already logged in, and will eventually hit this if the user doesn't have CP access permissions:</p>

<pre><code>// Otherwise send them wherever postLoginRedirect tells us
$postLoginRedirect = craft()-&gt;config-&gt;get('postLoginRedirect');
$returnUrl = UrlHelper::getSiteUrl($postLoginRedirect);
</code></pre>

<p>Which, you've got set to <code>account</code>, then it rinses and repeats given you the infinite redirect loop.</p>

CC BY-SA 3.0
2017-03-19T19:55:42.003Z
2017-03-19T19:55:42.003Z
Brad Bell
<p>I'm gonna probably find another way around this, but I'm still very new to Craft and want to ask if I'm missing something obvious. This is a commerce site that needs a front-end login. </p>

<p>I have an <code>account</code> template folder with some templating that looks like this (it's an extended layout, leaving out unnecessary lines): </p>

<pre><code>{# account/index.html #}
{% block main %}
    {% if craft.session.isLoggedIn %}
        {% include 'account/account.html' %}
    {% else %}
        {% include 'account/login_signup.html' %}
    {% endif %}
{% endblock %}
</code></pre>

<p>And an excerpt from my <code>general.php</code></p>

<pre><code>{# excerpt from my general.php file #}

'loginPath' =&gt; 'account',

'postLoginRedirect' =&gt; 'account',
</code></pre>

<p>When a logged-out user goes to <code>website.com/account</code> the <code>login_signup.html</code> page is spit out and a user can sign in (ignore the sign-up part). If they type in their info correctly, it leads to an <code>ERR_TOO_MANY_REDIRECTS</code> of <code>account</code> redirecting to <code>account</code>. This doesn't make sense to me, as both the login url and the post-login url point at the same path and load the same template, but the template should obviously handle the two situations differently. It should spit out the <code>account.html</code> template if the user is logged in, and if not, the <code>login_signup.html</code> template. These two template files have <strong>nothing</strong> in them right now, so it's not some other templating mistake.</p>

<p>If I remove either of the two config variables I presented in my <code>general.php</code> file, everything works but the routes I want aren't there.</p>

<p>I want a logged out user to visit <code>account</code>, get a sign in (<code>login_signup.html</code>) form they then use, and get redirected to <code>account</code> and the template will spit out the <code>account.html</code> template.</p>

<p><strong>Edit</strong> Basically, if a user is logged in with my <code>general.php</code> having those two configs set to the same path (<code>account</code>), this always results in too many redirects:</p>

<pre><code>{% block main %}
    {% if craft.session.isLoggedIn %}
        I'm logged in!
    {% else %}
        I should log in!
    {% endif %}
{% endblock %}
</code></pre>

<redirect><login><session>
Redirect issue with login and paths
# Redirect issue with login and paths

(Asked by: username_0 on 2017-03-18)

I'm gonna probably find another way around this, but I'm still very new to Craft and want to ask if I'm missing something obvious. This is a commerce site that needs a front-end login. 
I have an account template folder with some templating that looks like this (it's an extended layout, leaving out unnecessary lines): 
{# account/index.html #}
{% block main %}
    {% if craft.session.isLoggedIn %}
        {% include 'account/account.html' %}
    {% else %}
        {% include 'account/login_signup.html' %}
    {% endif %}
{% endblock %}

And an excerpt from my general.php
{# excerpt from my general.php file #}

'loginPath' => 'account',

'postLoginRedirect' => 'account',

When a logged-out user goes to website.com/account the login_signup.html page is spit out and a user can sign in (ignore the sign-up part). If they type in their info correctly, it leads to an ERR_TOO_MANY_REDIRECTS of account redirecting to account. This doesn't make sense to me, as both the login url and the post-login url point at the same path and load the same template, but the template should obviously handle the two situations differently. It should spit out the account.html template if the user is logged in, and if not, the login_signup.html template. These two template files have nothing in them right now, so it's not some other templating mistake.
If I remove either of the two config variables I presented in my general.php file, everything works but the routes I want aren't there.
I want a logged out user to visit account, get a sign in (login_signup.html) form they then use, and get redirected to account and the template will spit out the account.html template.
Edit Basically, if a user is logged in with my general.php having those two configs set to the same path (account), this always results in too many redirects:
{% block main %}
    {% if craft.session.isLoggedIn %}
        I'm logged in!
    {% else %}
        I should log in!
    {% endif %}
{% endblock %}

**Tags:** redirect, login, session


---

## 1 answers

### Answer by username_1 on 2017-03-19. Score: 0 | Accepted answer

Yeah... that won't work.
Craft currently uses the URI segments to determine special path like logging in, out, etc.
So when Craft sees account as the first segment in the URI, its going to treat that as a login request and execute what's in UsersController->actionLogin(), which will see that you're already logged in, and will eventually hit this if the user doesn't have CP access permissions:
// Otherwise send them wherever postLoginRedirect tells us
$postLoginRedirect = craft()->config->get('postLoginRedirect');
$returnUrl = UrlHelper::getSiteUrl($postLoginRedirect);

Which, you've got set to account, then it rinses and repeats given you the infinite redirect loop.


---

