• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

if URL variable is missing or does not match the criteria

Explorer ,
Apr 10, 2012 Apr 10, 2012

Copy link to clipboard

Copied

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?

Views

2.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 10, 2012 Apr 10, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 11, 2012 Apr 11, 2012

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 11, 2012 Apr 11, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 11, 2012 Apr 11, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 11, 2012 Apr 11, 2012

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 10, 2012 Apr 10, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 11, 2012 Apr 11, 2012

Copy link to clipboard

Copied

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


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation