Skip to main content
Inspiring
April 10, 2012
Question

if URL variable is missing or does not match the criteria

  • April 10, 2012
  • 3 replies
  • 2317 views

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?

    This topic has been closed for replies.

    3 replies

    pirula08Author
    Inspiring
    April 11, 2012

    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-devices-sold-in-q1

    how did they handle it? it looks like they just display an error message!?


    BKBK
    Community Expert
    Community Expert
    April 10, 2012

    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.]

    Owainnorth
    Inspiring
    April 10, 2012

    If it's an invalid URL then yes, you should display a 404 page and make sure you return a 404 header using CFContent or CFLocation. That way search engines will know to remove the page from their indexes.

    pirula08Author
    Inspiring
    April 11, 2012

    Owain how can I create a custom 404 page where I'll have my existing header and footer and say in the middle some 404 page not found message?

    I already have onMissingTemplate function in application.cfc but it returns a default coldfusion page!

    Owainnorth
    Inspiring
    April 11, 2012

    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.