1

I'm having trouble getting 404 pages to work. In Global Template Preferences I've set strict urls to yes (tried No as well) and have selected my 404 template.

My code on a single entry page is as follows.

{exp:channel:entries channel="services" disable="member_data|pagination|category_fields" limit="1" require_entry="yes"}

{if no_results}
    {redirect="404"}
{/if}

more code here
{/exp:channel:entries}

As far as I can tell this should go to a 404 page if I change the url to a non-existing url_title in the final segment. What happens instead is the page displays including header, footer and sidebar, but the content is empty.

any ideas?

--UPDATE-- full template code is in a pastie here.

  • Do you have an .htaccess in place? If so, it's worth removing it temporarily and testing again, see if you get different results. – Steve Mar 20 '13 at 15:28
  • no change - removed htaccess and viewed page using index.php in the url and behaved the same. – CreateSean Mar 20 '13 at 15:32
3

You'll need {if switchee_no_results}{redirect="404"}{/if} if nested inside switchee, due to switchee's parse="inward"

  • damn... didn't even think that switchee would be causing the trouble. Thanks James. – CreateSean Mar 20 '13 at 15:45
1

If you remove the {redirect="404"} from the conditional, and instead put something like 'no content' - does it show that?

whats the template group/page structure look like? I'm assuming you've got a 'services.group' and then servicing this code from an index.html (which is as I understand strict urls should work).

  • Carl, yes /services/ is a listing page /services/url_title is a single entry. When I removed the redirect code nothing appears in it's place despite being inside the conditional – CreateSean Mar 20 '13 at 15:35
1

I had this problem and was getting a blank white page in some but not all instances. My 404 uses an entry so the client can modify the 404 message - so my 404 consisted of an entries tag pulling in a specific entry_id. Because the 404 might be invoked from anywhere else on the site, its entries tag was being confused by unexpected URL segments, so it needed the dynamic="off" parameter.

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.