Skip navigation
pirula08
Currently Being Moderated

if URL variable is missing or does not match the criteria

Apr 10, 2012 1:52 PM

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?

 
Replies
  • Currently Being Moderated
    Apr 10, 2012 1:59 PM   in reply to pirula08

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 10, 2012 2:08 PM   in reply to pirula08

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

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 11, 2012 8:33 AM   in reply to pirula08

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 11, 2012 1:12 PM   in reply to pirula08

    It sounds like your onMissingTemplate method isn't set up properly then, as the sole purpose of it is to show your own error page rather than a built-in one.

     

    I'd suggest reading up on that, plenty of info out there.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points