Score:0

ErrorDocument not working for any error. Ubuntu Apache

uz flag

I'm having an issue with getting the ErrorDocument to work. I have tried most of the suggestions on most of the forms and posts. The only thing I know that I have that the others did not is the RewriteCond that was added by certbot.

I have done it in the past, but that was on an older version of ubuntu and was a self-signed site.

OS: Ubuntu 22.04

The current conf file

        ServerAdmin webmaster@localhost
        ServerName leofriclegends.com
        ServerAlias www.LeofricLegends.com www.leofriclegends.com LeofricLegends.com *.LeofricLegends.com *.leofriclegends.com 92.27.77.101
        DocumentRoot /var/www/leofriclegends.com/
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        ErrorDocument 405 /404.html
        ErrorDocument 500 /WebPageError.html
        ErrorDocument 502 /WebPageError.html
        ErrorDocument 503 /WebPageError.html
        ErrorDocument 504 /WebPageError.html

        <Files "404.html">
                <If "-z %{ENV:REDIRECT_STATUS}">
                        RedirectMatch 404 ^/404.html$
                </If>
        </Files>

        <Files "WebPageError.html">
                <If "-z %{ENV:REDIRECT_STATUS}">
                        RedirectMatch 404 ^/WebPageError.html$
                </If>
        </Files>


        RewriteEngine on
        RewriteCond %{SERVER_NAME} =*.LeofricLegends.com [OR]
        RewriteCond %{SERVER_NAME} =leofriclegends.com [OR]
        RewriteCond %{SERVER_NAME} =www.LeofricLegends.com [OR]
        RewriteCond %{SERVER_NAME} =LeofricLegends.com [OR]
        RewriteCond %{SERVER_NAME} =www.leofriclegends.com [OR]
        RewriteCond %{SERVER_NAME} =92.27.77.101 [OR]
        RewriteCond %{SERVER_NAME} =*.leofriclegends.com
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

apachectl -S:

VirtualHost configuration:
*:443                  leofriclegends.com (/etc/apache2/sites-enabled/leofriclegends.com-le-ssl.conf:2)
*:80                   is a NameVirtualHost
         default server leofriclegendslimitedserver.home (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost leofriclegendslimitedserver.home (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost industrialdimensions.co.uk (/etc/apache2/sites-enabled/industrialdimensions.co.uk.conf:1)
                 alias www.industrialdimensions.co.uk
                 alias www.IndustrialDimensions.co.uk
                 alias IndustrialDimensions.co.uk
                 wild alias *.IndustrialDimensions.co.uk
                 wild alias *.industrialdimensions.co.uk
         port 80 namevhost leofriclegends.com (/etc/apache2/sites-enabled/leofriclegends.com.conf:1)
                 alias www.LeofricLegends.com
                 alias www.leofriclegends.com
                 alias LeofricLegends.com
                 alias 92.27.77.101
                 wild alias *.LeofricLegends.com
                 wild alias *.leofriclegends.com
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

Sites/Tutorials I have looked at:

I'm sure I have missed something blatant, or I need an additional step due to certbot. So any help will be welcome.

Thank you

djdomi avatar
za flag
if this is a complete new instance remember to activate the required modules
La Phyzz avatar
uz flag
I believe I have, but again, I might have thought I have and haven't or missed something, or it changed; I will try and find the modules I need and check if they are activated.
La Phyzz avatar
uz flag
Ok, so while working on other things and even going away and coming back afresh, I still am unable to get the custom 404 page to work.
La Phyzz avatar
uz flag
Ok, So I have done everything I should to have to 404 page working. However, it does not. I am still determining why, but as far as I can tell, it should be working. I have gone back over it and done it from scratch, and it still does not work. Could someone point out what I might have missed or ask questions to try and work out what is going on, please, as I have a pounding headache from staring at way to many white screens trying to get this working?
La Phyzz avatar
uz flag
The site as a whole works fine, nothing wrong there, however, I can not get any custom error page to work.
La Phyzz avatar
uz flag
Can someone please help? I can not work out what the H I am missing, I have gone over EVERY B Line of code, triple-checked every guild AND STILL my 404 page is not working.
djdomi avatar
za flag
Does this answer your question? [How to create custom 404 error page for all users in apache?](https://serverfault.com/questions/48967/how-to-create-custom-404-error-page-for-all-users-in-apache)
Score:0
uz flag

After spending over a week on this issue, I found the problem comes from the fact that after using certbot it created another .conf file.

This file also needs the error code added to it to make the redirect work. So if anyone else has this problem, look for the file in your sites-enabled/YOUSITESNAME.COM-le-ssl.conf and add in the error handling there.

djdomi avatar
za flag
Sometimes, it will additionally help to use `apache2 -S` and the same with `-M` to see the full includes.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.