Apache htaccess Custom ErrorDocument not working properly for root home page 403 Error Issue and Solution

So I have a domain "testdomain.com".

Inside test domain.com's root is the following .htaccess:


Options +FollowSymLinks -Indexes
ErrorDocument 403 /launch/index.html

Order Deny,Allow
Deny From All
Allow From 192.168.1.2

When you visit anything other than root things work fine.  Eg. if you visit http://testdomain.com/somedirfile.html

It will show the right error in /launch/

But if you just visit the root you get the standard Apache Test page even though a 403 is returned.  The reason for this is because of an Alias "Error" in /etc/httpd/httpd.conf

Find this line and comment it out:

Alias /error/ "/var/www/error/"

What happens when visiting root is that it checks for a custom 403 error in /var/www/error/ and when it doesn't find one in there it returns noindex.html (the Apache test page).

However I don't know a better work-around what Apache then does after commenting out that alias is it insists in then looking inside your /www/document_root/error/ folder for a matching custom file.  If not it looks for a noindex.html in there.

So all I did was create a no index.html in an error folder within my document root.

This solves the issue but I am not sure of how to make a better solution.  I searched for hours modifying the vhost configuration but nothing worked or helped except the above.

These URLs below had the same issue:


https://www.linuxquestions.org/questions/linux-server-73/apache-403-on-root-serves-test-page-instead-of-forbidden-page-4175492016/
https://www.linuxquestions.org/questions/linux-server-73/apache-denied-ips-getting-test-page-914257/

 


Here is some of the troubleshooting process I went through:

 

I have an issue where I am only allowing a few IPs to view a website in .htaccess:


Options +FollowSymLinks -Indexes
ErrorDocument 403 /launch/index.html

Order Deny,Allow
Deny From All
Allow From 192.168.1.2


# Now it works if you go to http://url/somecrap it will take you to /launch/index.html
But if you just go to the reoot http://url/ or http://url you get the Apache Test page instead:



https://www.linuxquestions.org/questions/linux-server-73/apache-403-on-root-serves-test-page-instead-of-forbidden-page-4175492016/
https://www.linuxquestions.org/questions/linux-server-73/apache-denied-ips-getting-test-page-914257/

solution:
edit /etc/httpd/httpd.conf

# Customizable error responses come in three flavors:
# 1) plain text 2) local redirects 3) external redirects
#
# Some examples:
#ErrorDocument 500 "The server made a boo boo."
#ErrorDocument 404 /missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 http://www.example.com/subscription_info.html
#

#
# Putting this all together, we can internationalize error responses.
#
# We use Alias to redirect any /error/HTTP_<error>.html.var response to
# our collection of by-error message multi-language collections.  We use
# includes to substitute the appropriate text.
#
# You can modify the messages' appearance without changing any of the
# default HTTP_<error>.html.var files by adding the line:
#
#   Alias /error/include/ "/your/include/path/"
#
# which allows you to create your own set of files by starting with the
# /var/www/error/include/ files and
# copying them to /your/include/path/, even on a per-VirtualHost basis.
#

#Alias /error/ "/var/www/error/"


[root@serverdev error]# mv noindex.html noindex.html-bad
[root@serverdev error]# readlink -f .
/var/www/error


Alias /error/ "/var/www/error/"


#Alias /error/ "/var/www/error/"

<IfModule mod_negotiation.c>
<IfModule mod_include.c>
    <Directory "/var/www/error">
        AllowOverride None
        Options IncludesNoExec
        AddOutputFilter Includes html
        AddHandler type-map var
        Order allow,deny
        Allow from all
        LanguagePriority en es de fr
        ForceLanguagePriority Prefer Fallback
    </Directory>


Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

log#
[Sun Apr 08 04:09:43 2018] [error] [client 192.168.1.55] client denied by server configuration: /www/vhosts/vhosttest.com/httpdocs/
[Sun Apr 08 04:09:43 2018] [error] [client 192.168.1.55] client denied by server configuration: /www/vhosts/vhosttest.com/httpdocs/error
 


Tags:

apache, htaccess, custom, errordocument, solutionso, domain, quot, testdomain, followsymlinks, indexes, index, html, eg, http, somedirfile, alias, etc, httpd, conf, var, www, doesn, returns, noindex, commenting, insists, document_root, folder, matching, solves, searched, modifying, vhost, configuration, urls, https, linuxquestions, org, linux, server, serves, forbidden, ips, troubleshooting, allowing, website, url, somecrap, reoot, edit, customizable, responses, flavors, text, redirects, external, examples, cgi, bin, missing_handler, pl, subscription_info, internationalize, redirect, http_, multi, collections, includes, substitute, modify, default, adding, allows, copying, virtualhost, serverdev, mv, readlink, ifmodule, mod_negotiation, mod_include, directory, allowoverride, includesnoexec, addoutputfilter, addhandler, languagepriority, en, es, fr, forcelanguagepriority, fallback, additionally, encountered, apr, vhosts, vhosttest, httpdocs,

Latest Articles

  • How high can a Xeon CPU get?
  • bash fix PATH environment variable "command not found" solution
  • Ubuntu Linux Mint Debian Redhat Youtube Cannot Play HD or 4K videos, dropped frames or high CPU usage with Nvidia or AMD Driver
  • hostapd example configuration for high speed AC on 5GHz using WPA2
  • hostapd how to enable and use WPS to connect wireless devices like printers
  • Dell Server Workstation iDRAC Dead after Firmware Update Solution R720, R320, R730
  • Cloned VM/Server/Computer in Linux won't boot and goes to initramfs busybox Solution
  • How To Add Windows 7 8 10 11 to GRUB Boot List Dual Booting
  • How to configure OpenDKIM on Linux with Postfix and setup bind zonefile
  • Debian Ubuntu 10/11/12 Linux how to get tftpd-hpa server setup tutorial
  • efibootmgr: option requires an argument -- 'd' efibootmgr version 15 grub-install.real: error: efibootmgr failed to register the boot entry: Operation not permitted.
  • Apache Error Won't start SSL Cert Issue Solution Unable to configure verify locations for client authentication SSL Library Error: 151441510 error:0906D066:PEM routines:PEM_read_bio:bad end line SSL Library Error: 185090057 error:0B084009:x509 certif
  • Linux Debian Mint Ubuntu Bridge br0 gets random IP
  • redis requirements
  • How to kill a docker swarm
  • docker swarm silly issues
  • isc-dhcp-server dhcpd how to get longer lease
  • nvidia cannot resume from sleep Comm: nvidia-sleep.sh Tainted: Linux Ubuntu Mint Debian
  • zfs and LUKS how to recover in Linux
  • [error] (28)No space left on device: Cannot create SSLMutex Apache Solution Linux CentOS Ubuntu Debian Mint