Selectively handle 404s without a redirect

33 views
Skip to first unread message

Brian G

unread,
Feb 23, 2014, 5:10:52 PM2/23/14
to model...@googlegroups.com

I have an event listings website and from time to time, events are deleted or links to them are broken which generate soft 404 errors in Google webmaster tools.  Basically, the page isn't found and I currently result to redirect them back to an event search page.  I'd like to clean this up and properly handle it for Google by NOT redirecting but returning a 404 with a helpful event search page.  I can see how to create a default exception handler but that causes a cflocation.  I thought I could maybe use event.forward() but that too uses cflocation.

Is there a way in MG from a controller, when I don't find something in the database, to immediately execute a 404 handler WITHOUT a redirect?  E.g., the URL should stay the same with the "/this/url/doesnt/exist" and I could return a 404 header.  I don't want this site-wide, it should only handle my event listings.

The only thing I can think of right now is to create a proxy eventhandler... like

<event-handler name="display-event">
<broadcast>
  <message name="doCheckEventExists" />
</broadcast>
<results>
  <result name="isFound" do="display-event-found" />
  <result name="notFound" do="display-event-404" />
</results>
</event-handler>

This will work, but I would have to apply this proxy in quite a number of places in my eventhandlers XML.  I'd rather consolidate it down to the one place in my event controller where I determine whether the event id passed in the URL can be found, regardless of the kind of output (event info, event requirements, attendee list, results, etc).


Brian


todd sharp

unread,
Feb 23, 2014, 6:43:06 PM2/23/14
to model...@googlegroups.com

What's wrong with cflocation? That's the point of a status code - moved temporarily or permanently (301 or 302).

--
--
Model-Glue Sites:
Home Page: http://www.model-glue.com
Documentation: http://docs.model-glue.com
Bug Tracker: http://bugs.model-glue.com
Blog: http://www.model-glue.com/blog
 
You received this message because you are subscribed to the Google
Groups "model-glue" group.
To post to this group, send email to model...@googlegroups.com
To unsubscribe from this group, send email to
model-glue+...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en
---
You received this message because you are subscribed to the Google Groups "model-glue" group.
To unsubscribe from this group and stop receiving emails from it, send an email to model-glue+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

todd sharp

unread,
Feb 23, 2014, 6:44:19 PM2/23/14
to model...@googlegroups.com

If you want to go the event handler route look into event types. This is the use case they were created for.

Dan Wilson

unread,
Feb 24, 2014, 8:51:30 AM2/24/14
to model...@googlegroups.com
Maybe this is a good job for the built in ModelGlue.onRequest start event handler?

DW



Sunday, February 23, 2014 5:10 PM

Brian G

unread,
Feb 25, 2014, 12:57:37 AM2/25/14
to model...@googlegroups.com, to...@cfsilence.com

Because I want to return a 404, not a 301 or 302.  A redirect is precisely what I'm trying to avoid (and what Google is complaining about in the form of 'soft 404s').

It could be done in onRequestStart, but it applies to about a dozen event handlers.  I hadn't considered the eventtypes - I will give that a whirl - thanks!


Brian

todd sharp

unread,
Feb 25, 2014, 8:15:51 AM2/25/14
to model...@googlegroups.com

So adding statuscode="404" to cflocation won't work?

Jared Rypka-Hauer

unread,
Feb 25, 2014, 1:11:11 PM2/25/14
to model...@googlegroups.com
What Todd said… they added the ability to specify the HTTP result code in CF9, I think? It’s fairly recent, but it’s there…

J

On Feb 25, 2014, at 7:15 AM, todd sharp <to...@cfsilence.com> wrote:

So adding statuscode="404" to cflocation won't work?

On Feb 25, 2014 12:57 AM, "Brian G" <brian-...@vfive.com> wrote:

Because I want to return a 404, not a 301 or 302.  A redirect is precisely what I'm trying to avoid (and what Google is complaining about in the form of 'soft 404s').
...

Brian G

unread,
Apr 1, 2014, 6:05:29 PM4/1/14
to model...@googlegroups.com, to...@cfsilence.com
Huh, I've not seen this.  Thanks for the pointer, I will take a look.  I figured out something in the mean time but it's not that clean.

Brian G

unread,
Apr 2, 2014, 1:56:04 AM4/2/14
to model...@googlegroups.com, to...@cfsilence.com

Just to close the loop, no, this doesn't work.  It returns this error:

Attribute validation error in the cflocation tag.

Value of statuscode must be between 300 and 307.



On Tuesday, February 25, 2014 5:15:51 AM UTC-8, todd sharp wrote:
Reply all
Reply to author
Forward
0 new messages