ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

404 templates return 200 OK

September 28, 2010 1:49pm

Subscribe [3]
  • #1 / Sep 28, 2010 1:49pm

    AJP

    311 posts

    Heyo.

    I’m working on a site in EE 2.1 (latest build), and I’m running into issues with a proper 404 response code.
    I’m using Structure for my page hierarchy, if that’s necessary.
    Using NSM .htaccess, but I’ve disabled this for the time being.

    404 template is set (page_layouts/404) and strict URLs are set to Yes.

    If I visit domain.com/about-us (a real page), I get a 200 OK status.
    If I visit domain.com/billyjojimbob, I get a 200 OK status.
    If I visit domain.com/about-us/billyjojimbob, I get a 404 status.

    My template code is like this (at least the top part) of my default page template:

    {exp:channel:entries channel="pages" status="open|hidenav|footernav" limit="1" require_entry="yes" disable="categories|member_data|pagination"}
        {if no_results}
            {redirect="404"}
        {/if}
        {embed="embeds/page_header" body_class="innerPage" page_title="{if cf_pages_title_alt}{cf_pages_title_alt}{if:else}{title}{/if}" entry_id="{entry_id}"}
    {/exp:channel:entries}

    Any thoughts as to why segment_1 (an invalid segment_1) which is not a template group, returns 200 OK, but an invalid segment_2 then returns a 404?

    I’m kinda lost in response codes anyways, but some clarification here would help.

    Thanks!

  • #2 / Sep 28, 2010 11:28pm

    Cheif

    626 posts

    I believe “strict” 404 tests for the presence of a valid template group in segment_1 so if “about_us” isnt a template group it will error.
    segment_1 in your 1st 2 examples wont error because they are actual entries being displayed via your default template group (default doesnt need to show group name in URL)
    Your last example will error until you have a template group named “about_us”.


    .... I think 😉

  • #3 / Sep 29, 2010 8:00am

    AJP

    311 posts

    about-us is not a template group, but rather a page. I’m using structure, so if there is a difference between how they both show pages, now would be a good time to know. I’ll ping them as well.

    For the first example (domain.com/about-us) that is an actual page
    2nd and 3rd examples do not exist. Both should get 404 codes. EE is displaying my 404 template, but not the 404 codes.

  • #4 / Sep 29, 2010 8:34am

    Cheif

    626 posts

    I.m lost

    EE is displaying my 404 template, but not the 404 codes

    How’s that even possible, aren’t they one and the same ?

    I havent used the structure module so I can’t comment on its interaction with 404s in EE. But the documentation is pretty clear on how the “strict” feature works.

    If it’s the 404 that’s causing the angst, I’d personally look into using conditionals within my templates to test to make sure the URL matches an entry and {do domething} if it doesn’t.

  • #5 / Sep 29, 2010 8:55am

    AJP

    311 posts

    Per my code example, I’m using the recommended require_entry parameter, and the {if no_results}{redirect="404"}{/if} block in my template.

    about-us definitely is NOT a template group.

    The sticky part here is whether pages/structure entries return the appropriate status. I’ll try to ping the structure guys too.

  • #6 / Sep 29, 2010 7:33pm

    Brandon Jones

    5500 posts

    AJP, let us know what they say on that. I would also test without any URL rewriting by renaming .htaccess, as that could have an effect.

  • #7 / Sep 29, 2010 10:38pm

    Lisa Wess

    20502 posts

    Hey guys,

    I just wanted to step in and clarify a few things.

    Turning strict URLs on ensures that a valid template group is in segment 1.  By using the conditional on that page:

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

    ensures a valid template is called.

    You can then take that to segment 3 with the require_entry= parameter.

    Now, we’ve commonly seen the situation where using the “File and Directory check” method of removing index.php makes the 404 pages return status 200.  So that may be the case.  You should test without .htaccess in place - and with index.php in the URL - to rule that out.

    Otherwise, I would continue to follow up with Structure; or to remove Structure and get this feature working first, so that it’s a reduced test and easier to isolate where the issue is.

  • #8 / Oct 04, 2010 12:42pm

    AJP

    311 posts

    Thanks for the tips Lisa.
    Removing structure at this time isn’t an option, since the is 1. live, and 2. deployed and built.

    I’ll remove the .htaccess in the dev environment and see if that fixes things.

    How would you be returning appropriate headers using the pages module? Since page URLs may not (or in my case don’t) match template groups, it could conceivably be the same for the pages module as well. How would strict URLs match pages that don’t exist if they’re only using {segment_1}?

    Anywho, I’ll get back to you on .htaccess updates, and what the structure guys say as well.

    Thanks!

  • #9 / Oct 04, 2010 5:03pm

    Ingmar

    29245 posts

    Anywho, I’ll get back to you on .htaccess updates, and what the structure guys say as well.

    Very good, just keep us in the loop, please.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases