So my question is similar to the question posed in this page
Single ErrorDocument directive to catch all errors (.htaccess)
The above person was trying to get a dynamic error page.
However my question is slightly different (although it may still have the same answer).
I am with a shared web host who displays custom error pages by default with ads on it. I want errors to result in a real error response without ads. Do I need to individually do a:
ErrorDocument 404 /404.html
For each error? Or is there a way to just tell it to show a normal error message for all errors?
Is there some type of:
ErrorDirective JustOutputErrorInsteadOfRedirecting
Thank you in advance.
With ErrorDocument directive you can also display Your custom error messeage on the same page.
ErrorDocument 404 "Sorry, the page does not exist!"
ErrorDocument 403 "Ohh, you don't have permission to access this page!"
ErrorDocument 410 "Sorry, the page no longer exists"
You can also format these messges using html tags
ErrorDocument 404 "<h2>Sorry, the page does not exist!</h2>"
ErrorDocument 403 "<h2 style='color:blue'>Ohh, you don't have permission to access this page!</h2>"
ErrorDocument 410 "<p>Sorry, the page no longer exists</p>"
The message will appear on the same page.
Related
EDIT: This question has been solved. Please see my answer.
I have the file .htaccess that contains only the following line (I have added a custom 404 error page)
ErrorDocument 404 404.php
This is the code of the page 404.php:
<?php echo("file not found")?>
The problem is that if i type in my browser for example the url http://127.0.0.1/www/website/this_file_does_not_exist the page shows this line:
404.php
In other words, i see only the filename of the custom 404 error page instead of the content of the 404 error page.
I have already searched on stackoverflow for a solution without success.
How can i fix this problem?
From Apache documentation:
The syntax of the ErrorDocument directive is:
ErrorDocument <3-digit-code> <action>
where the action will be treated as:
A local URL to redirect to (if the action begins with a "/").
An external URL to redirect to (if the action is a valid URL).
Text to be displayed (if none of the above). The text must be
wrapped in quotes (") if it consists of more than one word.
In other words, if you're going to use a local URL it has to begin with a "/":
ErrorDocument 404 /404.php
I use host that has custom ErrorDocument settings already set in their httpd.conf and I can't edit this file (I don't have access) to solve the problem directly there.
Some background: I use an API that when something isn't right I manually set a responde code and print a json as error response to use in client side. Since I am triggering a response code (400 - Bad Request in my case) it falls directly in the catch of my Ajax request.
Their configuration for a custom 400 error page is causing this issue, the response of my API never returns because i got as response their custom page.
Is it possible to remove/reset or set it to show the page that triggered the error of an already set ErrorDocument via .htaccess?
On server where virtual server settings cannot be modified but .htaccess is accessible, this works for me:
ErrorDocument 401 default
ErrorDocument 402 default
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 500 default
ErrorDocument 501 default
ErrorDocument 502 default
ErrorDocument 503 default
ErrorDocument 504 default
Put it into .htaccess and it will reset error handling pages.
I am trying to create a customer 404 page in php that captures and can log into a database the page that was requested. I have this in my .htaccess file already:
ErrorDocument 404 http://mywebsite.com/notfound.php
What I am trying to do is append the requested URI to as a query string to the URL. I have tried this:
ErrorDocument 404 http://mywebsite.com/notfound.php?url=%{REQUEST_URI}
but the URL shows the literal text that I put in above. So I figured I would need some sort of flag at the end like [QSA] or something but all attempts result in a server error 500.
My ultimate goal is to capture the attempted broken link and the referring URL (which I can get from $_SERVER['HTTP_REFERER']) on the notfound.php page and log this into my database where I can pull a report of all links, hyperlinked or called via AJAX, that are broken or missing. I am able to do everything except get the requested URI of the actual link that caused the 404 error.
You shouldn't use ErrorDocument 404 with http:// in the target to avoid full redirect, like this:
ErrorDocument 404 /devsite/notfound.php
Then original 404 URI will be available to you as $_SERVER["REQUEST_URI"]
i am trying to show an custom error message when a page is not found and on my .htaccess i added a line like this:
ErrorDocument 404 error/404.html
but this just shows me 404.html on the screen instead rendering the 404.html page and if i write it like this
ErrorDocument 404 /error/404.html
than it gives me an error
Additionally, a 404 Not Found error was encountered while trying to
use an ErrorDocument to handle the request.
Is there another way to do this to show the actual error html page ? Thank you, Daniel!
As per your description it appears that your error folder is inside DOCUMENT_ROOT/site folder. In that case following full path ErrorDocument directive should work for you:
ErrorDocument 404 /site/error/404.html
can I vía .htaccess redirect when
Users finds an Internal Server Error
A not found page
Is that posible? if so, can someone help me with the rewrite rules?
edit
trying
ErrorDocument 500 /oohps.php
ErrorDocument 404 /where.php
and adding them at domain.com/oops.php and domain.com/where.php but still not loaded
Why not just use custom error responses via ErrorDocument?
ErrorDocument 500 /errors/internal-server-error.html
ErrorDocument 404 /errors/not-found.html
It is useful I am able to redirect to index page on 404 error(page not found) by modifying "ErrorDocument" in /etc/apache2/conf.d/localized-error-pages file.
Thanks.....