How should I handle blank space on the page when URL variable is missing or does not match the criteria? Should I simply display a message where missing content should be, say
Oops! The article you were looking for could not be found, do something with cferror or redirect to 404 page. Which way is SE friendly?
I have page http://www.website.com/news/title.cfm?news=whatever-news
with URL rewrite
http://www.website.com/news/whatever-news
I know this can only happen if article is deleted form DB or if someone insert or delete something within URL variable, for example
http://www.website.com/news/title.cfm?news=whatever----TEST JUST FOR FUN-news
in which case it will not match the criteria and will display nothing, 404 like content.
How should I handle this?
User-friendly error handling is one that:
1) Gives the user an indication, in the simplest terms, of what has gone wrong ['You supplied no news ID or an incorrect value for the news ID'];
2) Enables the user to take the next step [For example, by telling the user what to do next, or by including a link where he has to go next.]
as I can see you guys suggest two different approaches
ok can you please for example check this link
http://www.neowin.net/news/nokia-2-million-lumia-TEST-TEST-TEST-device s-sold-in-q1
how did they handle it? it looks like they just display an error message!?
Our approaches are actually the same. but BKBK goes further. The onMissingTemplate method will never fire in this case, as the page you're rewriting to actually exists, so what you're doing here is manually raising a 404. There are two ways of doing this; firstly you just do something like this:
<cfif FoundItems.RECORDCOUNT EQ 0 >
<cflocation url="/404.cfm" addtoken="false" statuscode="404" />
</cfif>
This will let people know that they've entered an invalid URL, and the statuscode will tell search engines that there's no page there.
What BKBK is suggesting is perhaps being more intelligent. Rather than just throwing them at a standard 404 page, try and handle it a little better. In your page where you would normally show the results, try and find any relevant results. See if there are any keywords in the URL you can search the database for, and display the links to those products on the page. Nothing groundbreaking here, just something a little more "web 2.0" than just saying "no, there's nothing here".
The only difference would be that you want to do this:
<cfheader statuscode="404" />
...before then going on to display your page. This is purely for the search engines.
Hope that explains it a little.
O.
"The onMissingTemplate method will never fire in this case" yes i know that, I've just asked for other non existing pages because it would be nice to have a custom page with CSS instead of the default one which onMissingTemplate generates.
first approach with cflocation is pretty much simple but I'm more interested in second one with cfheader and some error message. So, where should I put cfheader tag?
will this code do the trick:
<cfif FoundItems.RECORDCOUNT EQ 0 >
<cfheader statuscode="404" />
<cfset message = "Oops! The article you were looking for could not be found">
</cfif>
and somewhere on the page
<cfif isdefined ("message")>
<cfoutput>#message#</cfoutput>
</cfif>
Additionally I could display some links as you suggested.
North America
Europe, Middle East and Africa
Asia Pacific