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

  • systemd-journald high memory usage solution
  • How to Install FreePBX in Linux Debian Ubuntu Mint Guide
  • How To Install Cisco's CUCM (Cisco Unified Communication Manager) 12 Guide
  • Linux Ubuntu Redhat How To Extract Images from PDF
  • Linux and Windows Dual Boot Issue NIC Won't work After Booting Windows
  • Cisco CME How To Enable ACD hunt groups
  • How to install gns3 on Linux Ubuntu Mint
  • How to convert audio for Asterisk .wav format
  • Using Cisco CME Router with Asterisk as a dial-peer
  • Cisco CME How To Configure SIP Trunk VOIP
  • Virtualbox host Only Network Error Failed to save host network interface parameter - Cannot change gateway IP of host only network
  • Cisco CME and C7200 Router Testing and Learning Environment on Ubuntu 20+ Setup Tutorial Guide
  • Abusive IP ranges blacklist
  • How to Install Any OS on a Physical Drive from Windows Using VMware Workstation (Linux, Windows, BSD)
  • CDN Cloudflare how to set and preserve the real IP of the client without modifying application code on Apache
  • CentOS 7 fix Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=container error was 14: curl#6 -
  • Ubuntu Debian How To Install Recommended Packages Automatically
  • How to set Linux Ubuntu Redhat Debian Command Line http https socks proxy for yum apt
  • How to resize a pdf without losing much quality in Linux Mint Ubuntu Debian Redhat Solution
  • qemu: could not load PC BIOS 'bios-256k.bin' solution