Answers.Body: <p>The answer here was to redirect to another url using a different template rather than hitting the index template again, which was what was causing the loop.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-05T21:55:48.143Z
Answers.LastActivityDate: 2020-05-05T21:55:48.143Z
Answers.UserDisplayName: erwinheiser
Body: <p>On this multi-language site (NL, FR, EN) we're using the saml plugin to single sign on users into the craft site. That part is working fine. Every user has a preferred lanuage returned into a user custom field userLanguage.
  What I'm trying to do is simply redirect the French language users to <a href="https://mysite.com/fr" rel="nofollow noreferrer">https://mysite.com/fr</a> and the English language users to <a href="https://mysite.com/en" rel="nofollow noreferrer">https://mysite.com/en</a>
  In my index template I have the following</p>
  
  <pre><code>{% requireLogin %}
  
  {% if currentUser %}
      {% switch currentUser.userLanguage %}
  
        {% case "NL" %}
          {% redirect 'https://mysite.com'  %}
        {% case "FR" %}
          {% redirect 'https://mysite.com/fr'  %}
        {% case "EN" %}
          {% redirect 'https://mysite.com/en'  %}    
        {% default %}
           {% redirect 'https://mysite.com'  %} 
  
      {% endswitch %}
  {% endif %}
  {# rest of homepage template here #}
  </code></pre>
  
  <p>On visiting <a href="https://mysite.com/" rel="nofollow noreferrer">https://mysite.com/</a> I'm redirected to the sso page and after login back to <a href="https://mysite.com/" rel="nofollow noreferrer">https://mysite.com/</a> and there I get a "too many redirects" error, in firefox it's "The page isn’t redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete."
  What am I missing here?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-05-02T21:16:07.617Z
Comments.Text: Erwin, can't you check if a redirect is (still) needed? eg if userLanguage == 'NL' && URL == 'https://mysite.com' then no need to redirect?
Comments.UserDisplayName: Dave Driesmans
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-05-02T21:51:53.647Z
Comments.Text: Maybe it's because I'm redirecting to the same template. https://mysite.com/fr calls that index template again so it just keeps looping. Hmmm
Comments.UserDisplayName: erwinheiser
Tags: <login><redirect><redirection>
Title: Redirect user to language site of choice
ThreadText: # Redirect user to language site of choice
  
  (Asked by: username_0 on 2020-05-02)
  
  On this multi-language site (NL, FR, EN) we're using the saml plugin to single sign on users into the craft site. That part is working fine. Every user has a preferred lanuage returned into a user custom field userLanguage.
  What I'm trying to do is simply redirect the French language users to <https://mysite.com/fr> and the English language users to <https://mysite.com/en>
  In my index template I have the following
  
  ```
  {% requireLogin %}
  
  {% if currentUser %}
      {% switch currentUser.userLanguage %}
  
        {% case "NL" %}
          {% redirect 'https://mysite.com'  %}
        {% case "FR" %}
          {% redirect 'https://mysite.com/fr'  %}
        {% case "EN" %}
          {% redirect 'https://mysite.com/en'  %}    
        {% default %}
           {% redirect 'https://mysite.com'  %} 
  
      {% endswitch %}
  {% endif %}
  {# rest of homepage template here #}
  
  ```
  
  On visiting <https://mysite.com/> I'm redirected to the sso page and after login back to <https://mysite.com/> and there I get a "too many redirects" error, in firefox it's "The page isn’t redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete."
  What am I missing here?
  
  **Tags:** login, redirect, redirection
  
  > **Comments:**
  > **username_1**: Erwin, can't you check if a redirect is (still) needed? eg if userLanguage == 'NL' && URL == 'https://mysite.com' then no need to redirect?  
  > **username_0**: Maybe it's because I'm redirecting to the same template. https://mysite.com/fr calls that index template again so it just keeps looping. Hmmm  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-05-05. Score: 1
  
  The answer here was to redirect to another url using a different template rather than hitting the index template again, which was what was causing the loop.
  
  
  ---
  
  