Apache htaccess ErrorDocument - apache

When I include this if statements in my htaccess file, apache throws Internal Server Error 500:
ErrorDocument 500 /custom_50x.html
ErrorDocument 502 /custom_50x.html
ErrorDocument 503 /custom_50x.html
ErrorDocument 504 /custom_50x.html
<Files "custom_404.html">
<If "-z %{ENV:REDIRECT_STATUS}">
RedirectMatch 404 ^/custom_404.html$
</If>
</Files>
<Files "custom_50x.html">
<If "-z %{ENV:REDIRECT_STATUS}">
RedirectMatch 404 ^/custom_50x.html$
</If>
</Files>
What could be the reason?
The other problem with Apache is that even if a 404 webpage is added to ErrorDocument 404 directive, the status code which the server sends is 200 instead of 404.
The ErrorDocument 50* directives are not working also. Although I have set custom error pages for them, Apache still shows the default errors.

Related

Apache : Apache not respecting ErrorDocument directive, still get default 503 error page

We have a Spring-MVC application running simultaneously on 2 Apache tomcats, which are load-balanced by Apache Web server with mod_jk. We have such a setup on 2 servers, and on the 2nd server the ErrorDocument directive is being respected, but not on the first one. If I shut down tomcats, and then try to access the page, I am getting the default 503 error page, and not the customized one which I have placed in /var/www (Document root). Please note that the entire webapp runs under https.
000-default :
Listen 443
<VirtualHost _default_:443>
<Directory />
Options FollowSymLinks
AllowOverride All
ErrorDocument 503 /maintenance.html
ErrorDocument 404 /maintenance.html
ErrorDocument 500 /maintenance.html
</Directory>
JkMount /* loadbalancer
SSLEngine on
ErrorDocument 503 /maintenance.html
ErrorDocument 404 /maintenance.html
ErrorDocument 500 /maintenance.html
</VirtualHost>
<VirtualHost *:80>
ErrorDocument 503 /maintenance.html
ErrorDocument 404 /maintenance.html
ErrorDocument 500 /maintenance.html
</VirtualHost>
default-ssl :
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
ErrorDocument 503 /maintenance.html
ErrorDocument 404 /maintenance.html
ErrorDocument 500 /maintenance.html
<Directory />
Options FollowSymLinks
AllowOverride None
ErrorDocument 503 /maintenance.html
ErrorDocument 404 /maintenance.html
ErrorDocument 500 /maintenance.html
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
root#domain /var/www # ls
maintenance.html
If there is anything more required, please let me know. Thank you.
You are using JkMount /* which includes everything.
Use a less restrictive path or exclude /maintenance.html with mod_jk directives.

Custom error handling in httpd.conf

Tried implementing custom error handling in httpd.conf file. Able to
implement it only if I hard code the error message as follows:
ErrorDocument 502 "BAD ERROR MESSAGE!!"
Unable to implement if I use local redirect to custom error page- error.html as below.
ErrorDocument 502 /error.html
Didnot work either with the given sample error pages
ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var
Below is the part of httpd.conf file used
#Alias /error/ "<path>/www/error/"
Alias /error/include/ "<path>/www/error/"
<IfModule mod_negotiation.c>
<IfModule mod_include.c>
<Directory "<path>/www/error">
AllowOverride None
Options IncludesNoExec
AddOutputFilter Includes html
AddHandler type-map var
Require all granted
LanguagePriority en es de fr
ForceLanguagePriority Prefer Fallback
</Directory>
# ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var
# ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var
# ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var
# ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var
# ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var
# ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var
# ErrorDocument 410 /error/HTTP_GONE.html.var
# ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var
# ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var
# ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var
# ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var
# ErrorDocument 415 /error/HTTP_UNSUPPORTED_MEDIA_TYPE.html.var
# ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var
# ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var
# ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var
# ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var
# ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var
# ErrorDocument 404 /error/error.html
# ErrorDocument 502 "BAD ERROR MESSAGE!!"
# ErrorDocument 502 /error.html
ErrorDocument 403 "FORBIDDEN MESSAGE!!"
</IfModule>
</IfModule>
Tried testing by having error.html in /www/error/ and also in the document root which /www/html, but did not work.
Please suggest if the location of error.html is wrong or is there anything else to be added in http.conf.
Thanks in advance,
Swathi

Url rewrite is not working in some cases with XAMPP in Windows 7

I have a PHP website hosted at localhost on my Windows 7 PC, running XAMPP 1.8.2.
And I have rewrite rules as below:
Options -Indexes +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?rt=$1 [QSA,L]
</IfModule>
To rewrite the URL so it will always go into something like: http://mysite.com/index.php?rt=[controller]/[action]/[params]
It works prefect until I found it failed when processing url like: http://mysite.com/error/xxx. It returns a 404 status other than goes to http://mysite.com/index.php?rt=error/xxx. (I do NOT have an sub directory call error/ under my website root folder)
I carefully checked my PHP code and I am sure it is not the cause, and I upload my website to a remote server and everything is fine. So I am pretty sure something is not properly configured in my XAMPP (Apache), that makes the /error/xxx request was treated differently.
Also I found visiting http://mysite.com/error/ gives me 403 but http://mysite.com/[something_else]/ is fine.
Just in case, I paste my vhost.conf here as well:
<VirtualHost *:80>
DocumentRoot "/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "E:\htdocs\mysite.dev"
ServerName mysite.dev
</VirtualHost>
And related httpd.conf:
<Directory "E:\htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
Any help is appreciated!
Finally figure it out after wasting another hour on it!
There is configuration file called httpd-multilang-errordoc.conf under /xampp/apache/conf/extra, and inside it's something like this:
<IfModule alias_module>
<IfModule include_module>
<IfModule negotiation_module>
Alias /error/ "C:/xampp/apache/error/"
<Directory "C:/xampp/apache/error">
AllowOverride None
Options IncludesNoExec
AddOutputFilter Includes html
AddHandler type-map var
Require all granted
LanguagePriority en cs de es fr it ja ko nl pl pt-br ro sv tr
ForceLanguagePriority Prefer Fallback
</Directory>
ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var
ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var
ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var
ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var
ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var
ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var
ErrorDocument 410 /error/HTTP_GONE.html.var
ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var
ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var
ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var
ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var
ErrorDocument 415 /error/HTTP_UNSUPPORTED_MEDIA_TYPE.html.var
ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var
ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var
ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var
ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var
ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var
</IfModule>
</IfModule>
</IfModule>
The line Alias /error/ "C:/xampp/apache/error/" handles all the request matches domainname.com/error/ and rewrite it to C:/xampp/apache/error/.
Simply commenting out the line solves my problem. Not sure what it does but make things done.
From your last comment it sounds like Apache isn't even correctly configured to the path with your site!
You need to edit the Xampp\apache\conf\httpd.conf file.
First make a BACKUP copy of it.
Edit the line that starts with...
DocumentRoot "
..if it is a Windows machine and it uses / instead of \ retain those.
Then you need to edit the line that starts with...
<Directory "
Be aware that there is also a CGI version of this.
If you have correctly edited the file save and then restart Apache. Changes will NOT take effect until you restart Apache.

Custom Error Page for Apache

My .htaccess file:
AuthType Basic
AuthName "FORBIDDEN AREA"
AuthUserfile "../htdocs/forbidden/.htpasswd"
Require valid-user
<Directory /server>
Order allow,deny
Allow from all
</Directory>
ErrorDocument 500 /server/error500.html
ErrorDocument 404 /server/error404.html
ErrorDocument 404 /server/error404.html
ErrorDocument 402 /subscription_info.html
All my error pages are in htdocs/server/error***.html
But Apache shows its generic error page.
ErrorDocument 404 http://site.com/error.php as your recovery.

Apache Error Document is not working

I am running the apache2 webserver in the linux environment.I want to redirect the users to customized error pages.So have created the error pages & created the symbolic link in the htdocs also like this. static-files -> /app/static-files.
And in the httpd.conf file I have created the virtual host definition and included the error pages also like below:
NameVirtualHost m.mydomain.com:80
<VirtualHost m.mydomain.com:80>
DocumentRoot "/app/httpd-2.2.15/htdocs"
ServerName m.mydomain.com:80
<Directory "/static-files/html/error_pages">
Options FollowSymLinks
Order allow,deny
Allow from all
</Directory>
ErrorLog /app/httpd-2.2.15/logs/error_my_log
ErrorDocument 400 /static-files/html/error_pages/error_400.html
ErrorDocument 401 /static-files/html/error_pages/error_401.html
ErrorDocument 403 /static-files/html/error_pages/error_403.html
ErrorDocument 404 /static-files/html/error_pages/error_404.html
ErrorDocument 408 /static-files/html/error_pages/error_408.html
ErrorDocument 500 /static-files/html/error_pages/error_500.html
ErrorDocument 501 /static-files/html/error_pages/error_501.html
ErrorDocument 502 /static-files/html/error_pages/error_502.html
ErrorDocument 503 /static-files/html/error_pages/error_503.html
ErrorDocument 504 /static-files/html/error_pages/error_504.html
</VirtualHost>
When my app server is down,its not redirecting me to 503 customized error page.I am getting the server specific error page only.But if i put this ErrorDocument out of the virtual host definition its redirecting me to the customized error page. I am striking my head for 3 days.But not able to find the reason.I tried in all browsers.Anybody can help me ?
As you defined DocumentRoot to be "/app/httpd-2.2.15/htdocs", the error pages should be in this directory. Are you sure that the error pages are in this directory?
I'm not 100% sure but when you have an app server running behind Apache and when it is down you have a 404 not found.
It's not a 503 answer. 503 occurs when there is fault on the server (either Apache of the App server) such as load or anything that could happen following a miss configuration.