0

Having some issues forcing a 404 redirect when there are too many segments. Here is the page I am working on http://syntropy.highimpact.com/case-studies/aurora-flight-sciences/

I'm using the following code on the "case-studies" template:

{if segment_3 != ''}
  {redirect="404"}
{/if}

I thought doing this would force a redirect for any segments after segment 2. For instance, http://syntropy.highimpact.com/case-studies/aurora-flight-sciences/another-segment/ should be forcing a redirect, but instead it seems to be trying to load a page.

All of the other 404 redirect conditions are working fine. Any help would be much appreciated. Thanks.

  • Maybe just try {if segmemt_3} and see if that works – stuartmcd69 May 19 '16 at 0:12
0

Try some debugging to help. Add this code block to your template:

{site_url} / {segment_1} / {segment_2} / {segment_3}

{if segment_3}
    Condition 1 works <br><br>
{/if}

{if {segment_3}}
    Condition 2 works <br><br>
{/if}

{if "{segment_3}"}
    Condition 3 works <br><br>
{/if}

{if segment_3 != ''}
    Condition 4 works <br><br>
{/if}

{if {segment_3} != ''}
    Condition 5 works <br><br>
{/if}

{if "{segment_3}" != ''}
    Condition 6 works <br><br>
{/if}
  • None of these seem to work. Wondering if it has something to do with the template routing that I have set up. For this template I am using /case-studies/{title:alpha_dash} – Micah Kohne May 19 '16 at 15:47
  • Are you sure which template is being loaded if you have a 3rd segment? – jrothafer May 19 '16 at 15:50
  • So, if I add a slash in front of 404 it redirects to that page - it's just won't do the typical 404 redirect for a bad url. {if segment_3 != ''}{redirect="/404"}{/if} – Micah Kohne May 23 '16 at 16:58
0

Keep it clean and simple. Install Resource Router and then add conditions like this to your config file, a lot faster (it's processed before templates), all in one place, keeps your templates clean and far better/thorough handling.

$config['resource_router'] = array(
    'case-studies/:any/:all'      => $router->set404()
);

Read the docs, there's so much that can be caught and done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.