Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Plugins

Error plugin - Add more error pages

Solved by Aaron Dalton View solution

Started by Joachim Liedtke 8 years ago · 16 replies · 1278 views
8 years ago

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?

8 years ago

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?

8 years ago

@norrin there is a great plugin here
https://github.com/Perlkonig/grav-plugin-graveyard

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

8 years ago

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

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

8 years ago

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

8 years ago

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

8 years ago

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.

👍 1
8 years ago

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

8 years ago

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.

👍 1
8 years ago

Hi @perlkonig , that was quick!

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

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

8 years ago

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.

8 years ago

@perlkonig I changed my 'graveyard.yaml' to:

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

8 years ago Solution

But the config needs to be - /external*.

8 years ago

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

@Perlkonig:
You should just have to do - /external and be done with it (no wildcard needed).

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!

8 years ago

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

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 43 1 week ago
Plugins · by Xavier, 4 weeks ago
2 53 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1179 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 48 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 72 2 months ago