7 Replies Latest reply: Apr 11, 2012 1:12 PM by Owain North RSS

    if URL variable is missing or does not match the criteria

    pirula08

      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?

        • 1. Re: if URL variable is missing or does not match the criteria
          Owain North Community Member

          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.

          • 2. Re: if URL variable is missing or does not match the criteria
            BKBK MVP

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

            • 3. Re: if URL variable is missing or does not match the criteria
              pirula08 Community Member

              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!?

               


              • 4. Re: if URL variable is missing or does not match the criteria
                pirula08 Community Member

                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!

                • 5. Re: if URL variable is missing or does not match the criteria
                  Owain North Community Member

                  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.

                  • 6. Re: if URL variable is missing or does not match the criteria
                    pirula08 Community Member

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

                    • 7. Re: if URL variable is missing or does not match the criteria
                      Owain North Community Member

                      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.