Error plugin - Add more error pages


#1

I tried to add another error page to also catch 410 errors. I created a new 410-folder and an error.md file inside it.

Now I‘m stuck. How can I get the error plugin to display my custom 410-error-page, when an URL is called which I have declared as being gone in the .htaccess file?


#2

Great you are using this status code, most site owners don’t bother. It’s an important HTTP status!

Sounds like you followed directions in the README. Looking through the plugin code, I can’t see how that is triggered, so I have to question their accuracy.

Can you tell if your “gone” pages are being processed by Grav at all? It seems to me that if .htaccess is followed, Grav is left out. If you leave it to Grav, you don’t have a way to know it’s 410.

I can see a way this plugin could be extended or hacked if you want to go that way. The plugin uses the hook onPageNotFound, where you could probably check against a list of “other status” URLs (obtained from plugin config rather than .htaccess). Then alter the headers appropriately and load the right page/template. Is that something you’d be comfortable hacking?


#3

@norrin there is a great plugin here

This plugin lets you record a list of intentionally deleted routes. When those routes are requested, it emits a proper 410 GONE code instead of the more vague 404 NOT FOUND

You can investigate how @Perlkonig handle 410 errors

Hope it helps


#4

@hughbris
Here’s my setup:
In my ‘.htaccess’ I have rules like this

ErrorDocument 410 /410

Redirect Gone /articles/
RedirectMatch gone /extern*

Now, when I delete the ‘ErrorDocument’ line gone pages will result in the standard ‘Gone’ error message of the webserver. So far so good.

As soon as I add the ‘ErrorDocument’ line to the ‘.htaccess’, gone pages will result in the ‘404’ error message configured in the Grav Error plugin - instead of my ‘/410’ page.

When I call ‘/410’ page directly it displays perfectly well.


#5

@dimitrilongo
I installed the Graveyard plugin. It sounded promising in terms of comfortable maintenance. The plugin works like a charm for specific URLs, but unfortunately it doesn’t give me the flexibility of defining URLs like ‘/aggregator/’ or ‘/posts/*’ to catch all the pages starting with a certain pattern. This fact leaves this plugin useless for my scenario, because I don’t even know all the possible URLs to put into that list.


#6

I don’t think maintaining a list of specific URLs is a comfortable and flexible way for me to go as I don’t even know all the possible URLs at the moment.

Therefore I would like to rely on the flexibility ‘.htaccess’ gives me. Is this possible by any chance? I thougth the Error plugin would enable me to do just that …


#7

If you use htaccess, then Grav has nothing to do with it. You just need to make sure it plays nice with the Grav root htaccess.

There’s no reason I can think of why the plugin couldn’t be expanded to use wildcards. I just never thought of it at the time. I’ll take a look later today. Pull requests are also welcome.


#8

@Perlkonig that sounds cool.

I’d love to help, but my php knowledge is quite limited, so I wouldn’t even know where to start … I’m afraid. But if I can be of any help as ‘beta tester’ - just let me know. ;o)

Thanks a million for caring.


#9

v1.1.0 just released. It usually gets picked up by GPM at the top of the next hour. Let me know if this doesn’t meet your needs.


#10

Hi @perlkonig , that was quick!

I have put a ‘graveyard.yaml’ into ‘/user/config/plugins’ and it looks like this:

enabled: true
graveyard:
  - /article
  - /node/
  - /external*

http://mysite.com/article’ results in a 410 error page - as expected.
http://mysite.com/node/10’ results in a 404 error page, but should be a 410 error page.
http://mysite.com/external?xyz=123&abc=de’ results in a 404 error page, but should be a 410 error page.

Thanks a lot.


#11

You can’t just put a trailing slash. That second one needs to be - /node/*. I didn’t test with query parameters. They shouldn’t matter. You should just have to do - /external and be done with it (no wildcard needed). But I’ll double check later today.


#12

@perlkonig I changed my ‘graveyard.yaml’ to:

enabled: true
graveyard:
  - /node/*
  - /external

http://mysite.tld/node/10’ results now in a 410 error page. - Cool!
http://mysite.tld/node/100/10/1’ also results in a 410 error page. - Cool!
http://mysite.tld/external?xyz=123&abc=de’ results in a 410 error page. - Cool!
http://mysite.tld/external.php?xyz=123&abc=de’ results in a 404 error page, but should be a 410.


#13

But now you added .php, which changes the route. I just added - /demos/graveyard* to my test site config and it seems to work: https://www.perlkonig.com/dev/demos/graveyard.php?test=abc.


#14

Yeah, when I do ‘http://mysite.tld/node/external.php?xyz=123&abc=de’ I get a 410 too, but an ‘external.php?xyz=123&abc=de’ in the root directory gives me a 404.


#15

But the config needs to be - /external*.


#16

Allright. Got a bit confused here, 'cause you said

a bit further up … ;o)

I changed it and seems to work like a charm now.

Thank you ever so much for your effort in building this plugin. Cheers!


#17

No problem. I didn’t notice the added .php the first time 'round. I’m glad it’s working for you now.