small medium large xlarge

18 Oct 2010, 20:02
Frank Martin (1 post)

On page 84 you pull out the data for one article (the view page).

Not sure if I’m missing something or if this is covered later on in the book but for example when I visit the URL http://localhost/express/index.php/news_articles/view/uywieuqw <– Random string, it still loads an entry. Shouldn’t this go to a 404 page?

19 Oct 2010, 04:00
Ryan Irelan (218 posts)

It should but ExpressionEngine isn’t always smart about how it handles invalid url_titles. If the template (“view”) and template group (“news_articles”) are valid, EE still renders the template.

What you can do is use the @require_entry@ parameter in the Channel Entries tag pair. ExpressionEngine won’t show any entries if the url_title isn’t valid (i.e a match isn’t found in the database).

In addition to that you can use @no_results@ conditional to check for results and if there are none redirect to your 404 page.

{exp:channel:entries channel="foo" require_entry="yes" limit="1"}
 {if no_results}

That should get you what you need! :)

03 Nov 2010, 14:41
tom hanlon (20 posts)

This is the first time I have posted to this forum, so I may not be posting my question correctly. I’m running version 2.1.1, and I was confused by the link structure that you mentioned on pg 99. ~~~ news ~~~ . In my site I have an index.html page inside an folder which sits inside my default_site folder. Shouldn’t my navigation link to my articles starting with the folder, ~~~ <a href=”/>articles</a> ~~~ ? In the past, I used the {site_url} tag to link to my posts. Is this tag less efficient or are there any disadvantages of one over the other? Thanks for the help.

03 Nov 2010, 15:55
Ryan Irelan (218 posts)

Hi Tom, welcome!

There’s nothing wrong with using the @{site_url}@ variable. I’m just leaving it out and the browser just uses the domain of the site you’re viewing.

As far as the link goes, you never need to link directly to EE templates (like your example above) in the system directory. For your example, you’d want the link to be


which links to the index template of the articles template group.

04 Nov 2010, 13:22
tom hanlon (20 posts)

Thanks Ryan, I really like the simplicity of your method, and I’ve learned a lot from your book.

26 May 2011, 14:26
Farokh Saeed (9 posts)

I was having the same issue, that if a wrong url entry was entered in the url address bar, it still showed some article, it did not show 404 page.

I used your code Ryan, and now the 404 works perfectly and redirects perfectly when the url is wrong.