Answers.Body: <p><code>{% exit 403 %}</code> seems to be the answer! Seems so obvious now... <em>facepalm</em></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-21T10:14:39.907Z
Answers.LastActivityDate: 2016-03-21T10:14:39.907Z
Answers.UserDisplayName: Alec Ritson
Body: <p><strong>TL;DR</strong></p>
  
  <p>Is there a way to redirect with a status code and have the correct template load with the correct status code?</p>
  
  <hr>
  
  <p>I have template code which looks like this:</p>
  
  <pre><code>{% if slug is defined %}
   {% set entry = craft.entries.section('foobar').slug(slug).first() %}
   {% if not entry.editable %}
      {% redirect 403 %}
   {% endif %}
  {% endif %}
  </code></pre>
  
  <p>This works fine and redirects to the <code>403</code> template, but the problem is that is just redirects (changes the url) to <code>/403</code> with a status code of <code>302</code></p>
  
  <p>So <a href="https://craftcms.stackexchange.com/questions/8248/how-do-i-force-a-301-http-status-code-using-the-redirect-tag">I followed from this question</a> and used the second parameter to set the status code like so:</p>
  
  <pre><code>{% redirect 403 403 %}
  </code></pre>
  
  <p>Which sets the status code fine but now my 403 template doesn't load. If I try it with <code>404</code> the same problem applies. </p>
  
  <p>When I go to a <code>404</code> page which is handled by Craft (no redirect tag) then the status code is set correctly and my <code>404</code> template loads just fine.</p>
  
  <p>Is there a way to redirect with a status code and have the correct template load with the correct status code?</p>
  
Tags: <templating><redirect>
Title: Redirecting with http status code doesn't render template
ThreadText: # Redirecting with http status code doesn't render template
  
  (Asked by: username_0 on 2016-03-21)
  
  **TL;DR**
  
  Is there a way to redirect with a status code and have the correct template load with the correct status code?
  
  ---
  
  I have template code which looks like this:
  
  ```
  {% if slug is defined %}
   {% set entry = craft.entries.section('foobar').slug(slug).first() %}
   {% if not entry.editable %}
      {% redirect 403 %}
   {% endif %}
  {% endif %}
  
  ```
  
  This works fine and redirects to the `403` template, but the problem is that is just redirects (changes the url) to `/403` with a status code of `302`
  
  So [I followed from this question](https://craftcms.stackexchange.com/questions/8248/how-do-i-force-a-301-http-status-code-using-the-redirect-tag) and used the second parameter to set the status code like so:
  
  ```
  {% redirect 403 403 %}
  
  ```
  
  Which sets the status code fine but now my 403 template doesn't load. If I try it with `404` the same problem applies.
  
  When I go to a `404` page which is handled by Craft (no redirect tag) then the status code is set correctly and my `404` template loads just fine.
  
  Is there a way to redirect with a status code and have the correct template load with the correct status code?
  
  **Tags:** templating, redirect
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-03-21. Score: 2 | Accepted answer
  
  `{% exit 403 %}` seems to be the answer! Seems so obvious now... *facepalm*
  
  
  ---
  
  