0

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

La Phyzz
  • 1
  • 1
  • if this is a complete new instance remember to activate the required modules – djdomi Feb 09 '23 at 19:52
  • 1
    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 Feb 10 '23 at 12:24
  • 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 Feb 21 '23 at 14:23
  • 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 Feb 21 '23 at 15:02
  • The site as a whole works fine, nothing wrong there, however, I can not get any custom error page to work. – La Phyzz Feb 21 '23 at 15:07
  • 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. – La Phyzz Feb 23 '23 at 18:28
  • 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) – djdomi Feb 25 '23 at 13:35

1 Answers1

0

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.

La Phyzz
  • 1
  • 1
  • Sometimes, it will additionally help to use `apache2 -S` and the same with `-M` to see the full includes. – djdomi Feb 26 '23 at 14:16