User avatar
crazygamer24151
Posts: 10
Joined: Wed Apr 22, 2020 11:11 am

404 Error Page

Mon Sep 13, 2021 10:27 pm

I am making a website using apache and I am trying to set a custom 404 page. I tried to follow a previous post but it did not help.

pidd
Posts: 2642
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK
Contact: Website

Re: 404 Error Page

Tue Sep 14, 2021 6:01 am

Perhaps a link to what you have tried would help.

The error page is often specified in the .htaccess file using something like

ErrorDocument 404 /404.html

But it can be specified in the virtual host config instead, you probably need to restart or reload apache to pick this up.

User avatar
crazygamer24151
Posts: 10
Joined: Wed Apr 22, 2020 11:11 am

Re: 404 Error Page

Sun Sep 19, 2021 1:42 am

Here is what I previously tried: viewtopic.php?t=261236 when it mentioned the etc/apache2/sites-enabled/000-default file I noticed that I have 2. 000-default and 000-default.conf Which should I use?

pidd
Posts: 2642
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK
Contact: Website

Re: 404 Error Page

Sun Sep 19, 2021 2:50 am

You shouldn't edit in the sites-enabled folder, you should edit the /etc/apache2/sites-available/xxx.conf files

Apache2 will only look at .conf files.

After editing you need to reload apache, I normally use

Code: Select all

sudo systemctl restart apache2
Which is a bit over-the-top but ensures everything is cleaned up.

User avatar
DougieLawson
Posts: 41827
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: 404 Error Page

Sun Sep 19, 2021 8:03 am

pidd wrote:
Sun Sep 19, 2021 2:50 am
You shouldn't edit in the sites-enabled folder, you should edit the /etc/apache2/sites-available/xxx.conf files
Balderdash and poppycock.

It's a symbolic link from the enabled to the available configs so your editor will automagically edit the correct file.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on Twitter/LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

pidd
Posts: 2642
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK
Contact: Website

Re: 404 Error Page

Sun Sep 19, 2021 4:26 pm

DougieLawson wrote:
Sun Sep 19, 2021 8:03 am
pidd wrote:
Sun Sep 19, 2021 2:50 am
You shouldn't edit in the sites-enabled folder, you should edit the /etc/apache2/sites-available/xxx.conf files
Balderdash and poppycock.

It's a symbolic link from the enabled to the available configs so your editor will automagically edit the correct file.
Only if its been enabled, currently a2ensite only creates that link, there is no guarantee that will be the case in the future. The two directories are there for a reason, unless you know another reason?

User avatar
DougieLawson
Posts: 41827
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: 404 Error Page

Sun Sep 19, 2021 4:49 pm

pidd wrote:
Sun Sep 19, 2021 4:26 pm

Only if its been enabled, currently a2ensite only creates that link, there is no guarantee that will be the case in the future. The two directories are there for a reason, unless you know another reason?
One holds the configuration files. The other holds the symbolic links to the active configurations. a2ensite and a2dissite create or remove symbolic links in the sites-enabled. The main Apache2 configuration ONLY loads configurations from ../sites-enabled. It's the same for modules in ../mods-enabled. It's been like that since at least V2.2.

Why do you think Apache is going to change a system that works (and has been adopted by Lightty and NGinx)?

Once it's enable then editing the file in the ../*-enable directory causes the file in the matching ../*.available directory to be updated.

So what you wrote remains a load of nonsense.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on Twitter/LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

pidd
Posts: 2642
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK
Contact: Website

Re: 404 Error Page

Sun Sep 19, 2021 5:10 pm

DougieLawson wrote:
Sun Sep 19, 2021 4:49 pm
pidd wrote:
Sun Sep 19, 2021 4:26 pm

Only if its been enabled, currently a2ensite only creates that link, there is no guarantee that will be the case in the future. The two directories are there for a reason, unless you know another reason?
One holds the configuration files. The other holds the symbolic links to the active configurations. a2ensite and a2dissite create or remove symbolic links in the sites-enabled. The main Apache2 configuration ONLY loads configurations from ../sites-enabled. It's the same for modules in ../mods-enabled. It's been like that since at least V2.2.

Why do you think Apache is going to change a system that works (and has been adopted by Lightty and NGinx)?

Once it's enable then editing the file in the ../*-enable directory causes the file in the matching ../*.available directory to be updated.

So what you wrote remains a load of nonsense.
So are you saying you should never edit /etc/apache2/sites-available/xxx.conf and only edit /etc/apache2/sites-enabled/xxx.conf?

It is a totally unnecessary bodge which goes against the reasoning of the directory structure.

The purpose of /etc/apache2/sites-available is so that you can edit the config files whether it is enabled or not.

Just because something works doesn't mean it is the correct way to go about doing it.

I have seen setups whether the link hasn't been created and the config file exists purely in /etc/apache2/sites-enabled, this works fine but is non-standard. Telling people to edit files in /etc/sites-enabled is what leads people to unknowingly end up with non-standard configurations.

fbe
Posts: 681
Joined: Thu Aug 17, 2017 9:08 pm

Re: 404 Error Page

Sun Sep 19, 2021 7:25 pm

In a default /etc/apache2/apache2.conf all directories are configured with

Code: Select all

...
AllowOverride None
...
".htaccess" files are ignored in these directories. This is recommended for performance reasons (if performance matters). Server config files are read only once when the server starts. If you enable htaccess files in a directory, the server would need to search first for a htaccess each time when the server is asked for a file in that directory.
Htaccess files may be used in directories that are maintained by users that haven't got the permissions to edit the server config files.

Code: Select all

...
# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf
...
Only files (or symbolic links) ending with ".conf" are included from /etc/apache2/sites-enabled.

The whole configuration tree below /etc/apache2 is organized to allow the package maintainers to add or remove their configuration (e.g. for php, phpmyadmin, ...) without the need to edit one overall server config file during installation or removal of packages. You may follow the same approach to add your configuration. This would make it easier to reinstall your system, if you need to. Copy your files with settings into /etc/apache2/conf-available or /etc/apache2/sites-available and enable them with a2enconf or a2ensite. You can use a2disconf and a2dissite to disable config files.

The /etc/apache2/conf-available/localized-error-pages.conf has some commented examples for global configuration of error pages. You should use this or a similar file if you want to configure these pages globally. The /etc/apache2/sites-available/000-default.conf is for virtual host *:80 (HTTP). There is also a config file for HTTPS - default-ssl.conf. Of course you could add your configuration globally (outside the VitrualHost section) in 000-default.conf, but if you disable HTTP and enable HTTPS only, you would need to move your config lines from 000-default.conf to default-ssl.conf.

User avatar
crazygamer24151
Posts: 10
Joined: Wed Apr 22, 2020 11:11 am

Re: 404 Error Page

Mon Sep 27, 2021 12:57 am

I got it to work. Thank you for all your help.

Return to “Networking and servers”