I am trying to customize all the status codes (error codes) in Apache - Ubuntu 12.04 LTS.
The error message content I get on the browser for the error code 414 is:
Request-URI Too Large
The requested URL's length exceeds the capacity limit for this server.
I went through the file:
/etc/apache2/conf.d/localized-error-pages
to see the default file which shows this error, I found the below line:
ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var
When I go through the file
/usr/share/apache2/error/HTTP_REQUEST_URI_TOO_LARGE.html.var
I didn't find the same message viewed on the browser! How come? Where I can find the default message to edit it? I edited the above file and nothing changed on the browser!
One more thing, how can I customize this error to fit two different websites on the server (each website has different custom_error_414 page)
UPDATE: I removed the comments on the file localized-error-pages but the output didn't change, when I add any path in the file localized-error-pages like:
ErrorDocument 414 /var/www/myproject/error.php
it doesn't work, but when I add a normal string like:
ErrorDocument 414 "Long Request"
it does work! Please provide some codes and details on how to fix this issue and how to customize the 414 error for two websites.
UPDATE
Below is the output of
wget -O- -S ...
--2014-05-02 21:02:26-- http://localhost/error//HTTP_PRECONDITION_FAILED.html.var
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:80... failed: Connection refused.
Connecting to localhost (localhost)|127.0.0.1|:80... connected.
HTTP request sent, awaiting response...
HTTP/1.1 403 Forbidden
Date: Fri, 02 May 2014 21:02:26 GMT
Server: Apache
Vary: Accept-Encoding
Content-Length: 1
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1
2014-05-02 21:02:26 ERROR 403: Forbidden.
One more thing, I put the error page in /var/www/myproject/error.php but when I tried:
ErrorDocument 414 /var/www/myproject/error.php
It didn't work :( While
ErrorDocument 414 "Sorry, request is too long"
Worked out!
How come? Why it doesn't redirect me to the error page?
One more thing, I need to make for two websites two different pages, how can I achieve:
ErrorDocument 414 sites1 ==> /var/www/myproject1/error.php
ErrorDocument 414 sites2 ==> /var/www/myproject2/error.php
I want to put the error pages on my /var/www/project folder
I would greatly appreciate if you can send me direct steps to follow as I am not experienced system admin and I can't find documentation about this on the internet, it is very poor.
EDIT
Thanks for the detailed answer, I have followed your steps but I have minor issues would appreciate your input.
a. Below is the configuration file for the errors /etc/apache2/conf.d/localized-error-pages
#Alias /error/ "/usr/share/apache2/error/"
Options IncludesNoExec
AddOutputFilter Includes html
AddHandler type-map var
Order allow,deny
Allow from all
LanguagePriority en cs de es fr it nl sv pt-br ro
ForceLanguagePriority Prefer Fallback
ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var
ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.vr
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 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var
b. I have enabled the 3 mods successfully.
c. I have copied:
cp -R /usr/share/apache2/error/include /usr/share/apache2/include_site1
also
cp -R /usr/share/apache2/error/include /usr/share/apache2/include_site2
d. In site1
configuration in the page: /etc/apache2/sites-available/site1
, I added:
Alias /error/include "/usr/share/apache2/error/include_site1"
Alias /error/ "/usr/share/apache2/error/"
e. apache2ctl configtest
Syntax OK
f. Reloaded the Apache, loaded without errors.
g. wget -O- ..../error/HTTP_REQUEST_URI_TOO_LARGE.html.var
result is:
HTTP request sent, awaiting response... 200 OK
Length: 223 [text/html]
Saving to: `STDOUT'
0% [ ] 0 --.-K/s [an error occurred while processing this directive]
The length of the requested URL exceeds the capacity limit for
this server. The request cannot be processed.
[an error occurred while processing this directive] 100%[==============================================================================================================================>] 223 --.-K/s in 0s
2014-05-04 17:48:33 (73.1 MB/s) - written to stdout [223/223]
h. Tried from the browser: .../error/HTTP_REQUEST_URI_TOO_LARGE.html.var
The same result as step 8 but the in the browser
i. When I try placing huge request in the browser like:
...../site1/sj7xlekrjsuglkehgigl.........,
I get empty output on the browser and in the network (F12) I can see 414 error status
How can I get this working? I need to give the code 404 for the 414 error and I need to use (include) the customized PHP pages on each website, which is
/var/www/site1/not_found.php
Edit 2
I have added the below in sites available, but if I put long URL in browser, it doesn't redirect me to index.php nor to not_found.php page. I need the long URL error (414) to direct me to 404 page :( I am really upset I can't find any help online. Error like 414 doesn't work like 404 easily, they built inside the system.
404 is very easy for me! But can't configure 414!!!
ErrorDocument 404 /not_found.php
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
For example in sites-available the below doesn't work ErrorDocument 414 /not_found.php