httpd icon indicating copy to clipboard operation
httpd copied to clipboard

Feature Request: Customized 404 pages (without changing code and recompiling)

Open mojotx opened this issue 9 years ago • 13 comments

I would like the ability to have more control over the system-generated error pages, besides modifying C code myself and recompiling.

In other words, I don't want my "404 Not Found" pages saying, "OpenBSD httpd" at the bottom and using the Comic Sans font.

The nginx approach using the "error_page" keyword to specify a URI for a given HTTP code would be relatively straightforward to implement, I think. If there is nothing in the httpd.conf file for that server and a given return code, then the fall-back could still use the hard-coded version.

mojotx avatar Jan 28 '16 16:01 mojotx

I'm not going to send this as a patch myself because I don't need it but as an exercise I added such an option https://gist.github.com/tvlooy/8f5c9253f9e283eaee9a77e9721daa52

tvlooy avatar Nov 21 '16 19:11 tvlooy

Love spartan features and behavior of the httpd, but thanks for this request. 404 is IMO the only one error page which have to "communicate" with the user, provide him with, at least, a link to the site home page. Otherwise we lost this user in most cases.

vetelko avatar Jan 21 '18 13:01 vetelko

@reyk What are your thoughts on the changes that @tvlooy did as an exercise to add support for custom error pages?

IMO it would make a useful addition to httpd (8) and I'd excited to see it in one the the next OpenBSD releases.

afh avatar Jan 29 '18 01:01 afh

I throughly agree. I love the minimalist featureset of httpd, but having a fixed 404 error page is not very visitor friendly.

jaywilliams avatar Jan 30 '18 15:01 jaywilliams

what I would like is have an option to handle requests with factcgi if the requested location is not a file or directory. Like in Apache:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

tvlooy avatar Jan 30 '18 16:01 tvlooy

@tvlooy ... or try_files in nginx

vetelko avatar Jan 31 '18 12:01 vetelko

@vetelko said everything. This is a small improvement very useful for visitor. Hope to see this in httpd too.

B4rb3rouss avatar Feb 21 '18 15:02 B4rb3rouss

I agree, this would be very useful. I have a client's new site running on httpd but there are links out there in the wild to pages from their old site that no longer exist. I'd love to be able to give visitors a custom 404 page with a link to the current homepage if they happen to click on them.

ghost avatar Apr 22 '18 13:04 ghost

@jsfierro in this case you should try to redirect (if old url structure allows this) user using 301 code from old url to new url or to homepage

vetelko avatar Apr 22 '18 13:04 vetelko

@vetelko

That's that what I'm doing now, but it's kind of tricky. The old site had tons of pages, with lots of duplicate content, non-obvious subdirectory names, etc. I have many of the important ones redirected, but there's a lot I am missing, so a custom 404 to catch those would be great.

ghost avatar Apr 22 '18 14:04 ghost

if som logical pattern in old url strcuture is missing than you are right. can't you switch to nginx for now? I doubt custom 404 via directive in httpd.conf will be solved anytime soon :(

vetelko avatar Apr 22 '18 15:04 vetelko

Just want to note that @tvlooy's patch is working brilliantly for me as of 6.3 httpd.

Thank you! Hopefully this is looked at for a future release.

Ranguvar avatar Jun 20 '18 01:06 Ranguvar

Updated for 6.4: https://gist.github.com/Ranguvar/7fdec9c8f0a55edad4cdabb4c5c59f79 Not working for me on 6.4, may be patch issue or something else.

Ranguvar avatar Oct 23 '18 20:10 Ranguvar