Custom notfound handler

16 views
Skip to first unread message

Paul Lam

unread,
Mar 22, 2015, 1:16:29 PM3/22/15
to apostr...@googlegroups.com
For the career section on our site, we need to show a custom page/message when there is 404, I am thinking we can write a custom notfound handler to match the URLs, is this possible?
I am new to apostrophe, looked at the custom module in tutorial, it only mention self.notfound can be set to true/false, where can I find a sample for writing custom notfound handler if possible?
Thanks for any help in advance.

Tom Boutell

unread,
Mar 22, 2015, 10:18:44 PM3/22/15
to apostr...@googlegroups.com

Look at the coffee for the apostrophe-magic-redirect module, which does something similar.

--
You received this message because you are subscribed to the Google Groups "apostrophenow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apostropheno...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paul Lam

unread,
Mar 23, 2015, 5:58:11 PM3/23/15
to apostr...@googlegroups.com
hi Tom,

Thanks for your help, I tried your magic and seems we are heading to the right direction.
Now the problem is, the "notfound" handler works for regular page, for example if we have a regular page http://example.com/xxxxx, our custom notfound handler works perfectly, however if the pages are based on snippets then seems not working. For example our career pages extend blog module, then every page under "http://example.com/careers/job/xxxxx" go to regular 404 page only, seems our custom notfound handler doesn't kcik in.

do you have any idea? Thanks for and help in advance.

Paul

Tom Boutell

unread,
Mar 25, 2015, 11:22:03 AM3/25/15
to apostr...@googlegroups.com
I've just published a fix for this. The apostrophe-pages module needed an update to let custom notfound handlers handle cases where there technically is a page, but the module powering it has specifically requested it be treated at as a 404.
--


THOMAS BOUTELL, DEV & OPS
P'UNK AVENUE | (215) 755-1330  |  punkave.com

Paul Lam

unread,
Mar 25, 2015, 8:54:17 PM3/25/15
to apostr...@googlegroups.com
Tom, thank you very much, I tried your fix, and the custom redirect work fine now.
We have one more question, is there a way to go back to default 404 page in our custom handler? because at the moment, we define some patterns in custom handler, if doesn't meet any pattern, then shall go back to default 404. With newest fix, if no matches, then it shows bad gateway page.

thanks again!

Paul

Tom Boutell

unread,
Mar 25, 2015, 10:23:12 PM3/25/15
to apostr...@googlegroups.com
You can set req.template to "notfound".

Paul Lam

unread,
Mar 26, 2015, 5:28:53 PM3/26/15
to apostr...@googlegroups.com
hi Tom,
It works and thank you very much for your hep.
Without your help, I don't think we could get this done. much appreciated!

Paul

Paul Lam

unread,
Mar 30, 2015, 8:24:51 PM3/30/15
to apostr...@googlegroups.com
hi Tom, I have another quick question, is there a way to set HTTP status code in redirect? 
Seems currently when we set ref.redirect, the status code is 302 temporarily moved, but we actually want to change to 301 Moved Permanently, 
I tried to change  ref.statusCode = 301, but seems  no effect. Is it possible to do that?
Thanks. 

Paul 

Tom Boutell

unread,
Mar 31, 2015, 11:50:44 AM3/31/15
to apostr...@googlegroups.com
Not at the moment. It would be a pretty simple pull request to the pages module though!

Tom Boutell

unread,
Mar 31, 2015, 11:51:07 AM3/31/15
to apostr...@googlegroups.com
(I personally avoid 301's unless the client absolutely insists because they are so hard to get out a browser's cache if they are wrong.)
Reply all
Reply to author
Forward
0 new messages