I've been looking at the civetweb user guide, and it looks like it would be possible to create a 404 page (perhaps asking people if they were looking for http://pi.hole/admin).
Or perhaps it would be better to add to the initial configuration, something like:
error_page = 404 /admin
So that people would never see a clunky 404 webpage. (I'm not entirely sure where that would go in the embedded civetweb, but I'd be happy to learn on the fly and do the PR if someone could point that out.)
A quick look into pihole.toml tells us that we are generally not afraid to add more options
Your idea may be useful for some, but how often would they see a 404 (a plain request on pi.hole will already be redirected). We don't have this so far in case users are hosting other stuff besides Pi-hole's web interface. However, if we decide this is worth adding, I'd prefer a simple user experience by maybe simply adding a new boolean config option for the redirect. Whether it should default to true or false can then be discussed as well.
Could you point me to the location where the line you mentioned is documented?
I can only finde the documentation for error_pages but this would not quite work here (highlighting added):
This option may be used to specify a directory for user defined error pages. To specify a directory, make sure the name ends with a backslash (Windows) or slash (Linux, MacOS, ...). The error pages may be specified for an individual http status code (e.g., 404 - page requested by the client not found), a group of http status codes (e.g., 4xx - all client errors) or all errors.
The corresponding error pages must be called error404.ext, error4xx.ext or error.ext, whereas the file extension may be one of the extensions specified for the index_files option.
A quick code check confirms that this config option is working as described: one needs to specify a directory and therein, the webserver will search for aforementioned files until it finds one (or not).
Hmmm...I appear to have been a victim of an AI search result because when I tried to recreate what I found about error_pages redirect, the only thing I'm getting Google AI telling me to put something into an .htaccess file, which Civetweb doesn't have. I'll do some more digging to see if I can find a supportable solution. Apologies.
Thanks in advance for indulging a non-expect dabbler like me.
Here's what I've found out (and tested) using the stand-alone command line (not the embedded in Pi-hole option) in Debian. I believe the error_pages option has to be specified before Civetweb will look for error_pages. Thus, a command line civetweb -document_root /var/www/html/civetweb will always return default error pages. But the command line for the error pages doesn't work great because it always defaults to the directory of the command, not the specified document _root.
But, you can use a configuration file, and call the configuration file in the command. Thus, for a civetweb.conf in temp, with the content:
Civetweb will look for error pages in the document root. This appears to be good for the FTL code noted above because all we need is another line:
"error_pages", config.webserver.paths.webroot.v.s,
since we already have the root.
We'd also need to add a page in document root (not another directory). I got a page working with html but I don't know what the corresponding one would be in what Pi-hole uses (.lua?).
In .html, a file error404.html having the content {html} {meta http-equiv="Refresh" content="0; url='/'" /} {/html} will produce a redirect to the document_root. [Brackets {} instead of <> to make visible.]
To summarize, I think the code could be updated with just a few changes to produce a 404 redirect, if desired.
Thanks for the hard work. I'll play around with the "pretty" page. Remains to be seen whether it will be less "pretty" or more "pretty" but it will likely mention something about entering Romulan territory.