0

I have 'strict urls' enabled in my build, with a 404 pages set up.

For some reason, if an incorrect entry segment is used within a template group URL it is displaying the latest entry.

For instance if the following is loaded (doesn't actually exist):

http://www.domain.com/greeting-cards/view/entry-1

It loads the latest entry created in that channel.

How can I have it display a 404 error?

1

The exp:channel:entries just filter its listed entries if there is one entry that matches the segments 2 or 3. Otherwise it will list how many entries the limit parameter allow.

If you want to return a 404, you need to use if no_results conditional variable and the require_entry parameter:

{exp:channel:entries limit="1" require_entry="yes" [...] }
     [...]
     {if no_results}
         {redirect="404"}
     {/if}
{/exp:channel:entries}

From the docs:

This parameter tells the channel tag that it should expect the URL to contain a valid entry ID or a valid URL title. If an ID is not found in the URL, the tag will not display any data. Normally, the channel tag will show something, even if the URL doesn’t point to a particular entry. For example, your main channel page will typically show several of your most recent entries. Whereas your “single entry” pages, like your comment page, will show a single entry based on information in the URL. However, if one of your single entry pages is requested, but it doesn’t contain a valid ID, this parameter will tell the tag that you do not wish the template to display anything.

Note

You will often use this parameter in conjunction with the if no_results conditional.

| improve this answer | |

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.