Custom Error Page for Apache - 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.

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.

Why doesn't this .htaccess code work?

Was given this code to use and used it without changing it
<FilesMatch "^(?!log_request\.php).*$">
AuthUserFile /protect/.htpasswd
AuthName "Tester's test test"
AuthType Basic
Require valid-user
</FilesMatch>
ErrorDocument 401 /log_request.php
I have no idea what the function of the FilesMatch "^(?!log_request.php).*$" line is but other than that the files should match. When i try to view the .htpasswd file i get Internal Server Error.
Try this code:
<FilesMatch "^(?!.*?log_request\.php).*$">
AuthUserFile /protect/.htpasswd
AuthName "Tester's test test"
AuthType Basic
Require valid-user
</FilesMatch>
ErrorDocument 401 /log_request.php
(?!...) is a negative lookahead that makes sure Basic Auth code is applied for all the files except log_request.php
Option 2 Use SetEnvIfNoCase:
SetEnvIfNoCase Request_URI "^/(?!log_request\.php).*" HANDLE401
AuthUserFile /protect/.htpasswd
AuthName "Tester's test test"
AuthType Basic
Require valid-user
Satisfy any
Order allow,deny
Allow from all
Deny from env=HANDLE401
You could use ErrorDocument 401 /log_request.php to send all those requests to some PHP script.
Take a look at this tutorial for more info: http://www.askapache.com/htaccess/htaccess-htpasswd-basic-auth.html

<VirtualHost> cannot occur within <VirtualHost> section

after I try to use my own vhost.confic instead of using the generated one from Plesk, I just copy the last_httpd.include file and made some modifications - change the document root. But the /usr/local/psa/admin/sbin/httpdmng --reconfigure-domain redmine.newslab.cz get some error
2013-11-28T10:52:28+01:00 ERR (3): Apache config (13856323480.31924600) generation failed: Syntax error on line 1 of /var/www/vhosts/redmine.newslab.cz/conf/vhost.conf:
<VirtualHost> cannot occur within <VirtualHost> section
Syntax error on line 1 of /var/www/vhosts/redmine.newslab.cz/conf/vhost.conf:
<VirtualHost> cannot occur within <VirtualHost> section
vhost.conf file
<VirtualHost *:80 >
ServerName "redmine.newslab.cz"
ServerAlias "www.redmine.newslab.cz"
ServerAlias "ipv4.redmine.newslab.cz"
UseCanonicalName Off
<IfModule mod_suexec.c>
SuexecUserGroup "redmine.newslab" "psacln"
</IfModule>
ServerAdmin "admin#newslab.cz"
DocumentRoot "/var/www/vhosts/redmine.newslab.cz/httpdocs/redmine/public"
CustomLog /var/www/vhosts/redmine.newslab.cz/statistics/logs/access_log plesklog
ErrorLog "/var/www/vhosts/redmine.newslab.cz/statistics/logs/error_log"
<IfModule mod_userdir.c>
UserDir "/var/www/vhosts/redmine.newslab.cz/web_users"
</IfModule>
ScriptAlias "/cgi-bin/" "/var/www/vhosts/redmine.newslab.cz/cgi-bin/"
Redirect permanent /plesk-stat https://redmine.newslab.cz/plesk-stat
Redirect permanent /webstat https://redmine.newslab.cz/webstat
Redirect permanent /webstat-ssl https://redmine.newslab.cz/webstat-ssl
Redirect permanent /ftpstat https://redmine.newslab.cz/ftpstat
Redirect permanent /anon_ftpstat https://redmine.newslab.cz/anon_ftpstat
Redirect permanent /awstats-icon https://redmine.newslab.cz/awstats-icon
<IfModule mod_ssl.c>
SSLEngine off
</IfModule>
SetEnv PP_CUSTOM_PHP_INI /var/www/vhosts/redmine.newslab.cz/etc/php.ini
<IfModule mod_fcgid.c>
FcgidInitialEnv PP_CUSTOM_PHP_INI /var/www/vhosts/redmine.newslab.cz/etc/php.ini
FcgidMaxRequestLen 16777216
</IfModule>
<Directory /var/www/vhosts/redmine.newslab.cz/httpdocs/redmine/public>
<IfModule mod_perl.c>
<Files ~ (\.pl$)>
SetHandler perl-script
PerlHandler ModPerl::Registry
Options ExecCGI
allow from all
PerlSendHeader On
</Files>
</IfModule>
<IfModule mod_python.c>
<Files ~ (\.py$)>
SetHandler python-program
PythonHandler mod_python.cgihandler
</Files>
</IfModule>
<IfModule mod_fcgid.c>
<Files ~ (\.fcgi)>
SetHandler fcgid-script
Options +FollowSymLinks +ExecCGI
</Files>
</IfModule>
<IfModule mod_fcgid.c>
<Files ~ (\.php)>
SetHandler fcgid-script
FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .php
Options +ExecCGI
allow from all
</Files>
</IfModule>
Options -Includes +ExecCGI
</Directory>
<Directory "/var/www/vhosts/redmine.newslab.cz/statistics">
AuthType Basic
AuthName "Domain statistics"
AuthUserFile "/var/www/vhosts/redmine.newslab.cz/pd/d..httpdocs#plesk-stat"
require valid-user
</Directory>
Alias /error_docs /var/www/vhosts/redmine.newslab.cz/error_docs
ErrorDocument 400 /error_docs/bad_request.html
ErrorDocument 401 /error_docs/unauthorized.html
ErrorDocument 403 /error_docs/forbidden.html
ErrorDocument 404 /error_docs/not_found.html
ErrorDocument 500 /error_docs/internal_server_error.html
ErrorDocument 405 /error_docs/method_not_allowed.html
ErrorDocument 406 /error_docs/not_acceptable.html
ErrorDocument 407 /error_docs/proxy_authentication_required.html
ErrorDocument 412 /error_docs/precondition_failed.html
ErrorDocument 414 /error_docs/request_uri_too_long.html
ErrorDocument 415 /error_docs/unsupported_media_type.html
ErrorDocument 501 /error_docs/not_implemented.html
ErrorDocument 502 /error_docs/bad_gateway.html
ErrorDocument 503 /error_docs/maintenance.html
</VirtualHost>
Do have anybody idea what is wrong. Thx
It is simple. Your vhost.conf is included inside the one generated by Plesk, it doesn't replace the Plesk config. That means you need to strip your vhost.conf from VirtualHost directive and other duplicated content. Keep there only directives which you need and which Plesk doesn't add itself.

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 in Apache2 for 401

Here's the relevant part of the .htaccess file:
AuthUserFile /var/www/mywebsite/.htpasswd
AuthGroupFile /dev/null
AuthName protected
AuthType Basic
Require valid-user
ErrorDocument 400 /var/www/errors/index.html
ErrorDocument 401 /var/www/errors/index.html
ErrorDocument 403 /var/www/errors/index.html
ErrorDocument 404 /var/www/errors/index.html
ErrorDocument 500 /var/www/errors/index.html
Docuement root is set to /var/www/mywebsite/web, it's on of many vhosts. I can navigate to the index.html page.
All I'm seeing is the generic Apache 401 page, any thoughts.
EDIT: This is the error message in my browser:
Authorization Required
This server could not verify that you
are authorized to access the document
requested. Either you supplied the
wrong credentials (e.g., bad
password), or your browser doesn't
understand how to supply the
credentials required.
Additionally, a 401 Authorization
Required error was encountered while
trying to use an ErrorDocument to
handle the request. Apache/2.2.9
(Debian) PHP/5.2.6-1+lenny8 with
Suhosin-Patch Server at www.dirbe.com
Port 80
Make sure that /var/www/errors is readable by the apache user and include this in your apache configuration:
<Directory /var/www/errors>
Order allow,deny
Allow from all
</Directory>
ErrorDocument takes in a absolute URL path instead of a file path. So it should be:
ErrorDocument 404 /error/error.html
Assuming under your document root is a /error/error.html file.
This question (and answers and comments) helped me a bunch, thanks much!
I solved a slightly different way, and wanted to share. In this case, we needed to provide a custom 401 error document and the root path needed to be proxied to a backend app.
So, for example, http://example.com needed to serve content from http://internal-server:8080/. Also, http://example.com needed to be protected using Basic Auth with a custom 401 error document.
So, I created a directory named "error" in the DocumentRoot. Here's the relevant lines from the vhost:
ErrorDocument 401 /error/error401.html
# Grant access to html files under /error
<Location "/error">
Options -Indexes
Order Deny,Allow
Allow from all
</Location>
# restrict proxy using basic auth
<Proxy *>
Require valid-user
AuthType basic
AuthName "Basic Auth"
AuthUserFile /etc/apache2/.htpasswd
</Proxy>
# Proxy everything except for /error
ProxyRequests Off
ProxyPass /error !
ProxyPass / http://internal:8080/
ProxyPassReverse / http://internal:8080/