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. Isearched 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_.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_.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/"




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



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

  • scp: ambiguous target error and solution
  • VirtualBox How To Add iSCSI Storage using VBoxManage
  • iSCSI on Centos 7 Configuration and Setup Guide for Initiator and Target
  • Python and BeautifulSoup4's BS4's Decompose Method To Remove Unwanted Inner Tags
  • httpd AH00534: httpd: Configuration error: No MPM loaded. solution
  • bash script to remove modules from httpd.conf that are not actually installed
  • bash scripting how to create a function
  • Centos 7 PHP MySQL Not Working Solution
  • Bash How To Cut or Split Natively And Get The LAST Field
  • Bash Script How To Manipulate Text/Strings By Searchig and Replacing Natively
  • How Does Cisco CUCM (Cisco Unified Communication Manager) Work?
  • What DNS Options Does Active Directory Offer in Windows Server 2008,2012,2016 ?
  • syntax error, unexpected T_SL in PHP Solution
  • grep regular expression match number range between specific numbers
  • bash how to print out lines of text within a range from the first occurrence
  • bash script how to to check LAN computers for open ports
  • MySQL Using mytop Debug Source of High IO and Slow Performance
  • How To Mathematically Convert and Calculate Binary Value To Decimal Value
  • systemd management using systemctl and journalctl to check systemd logs
  • css how to format code in the code tag