This is my error page i dont know exactly what is but i want to redirect this kind of error to 404.html page:
I have created a 404 error page name "404.html". I want to redirect to this if no file or folder exist in my server.
Where do I have to place this page (404.html)?
Is it possible to redirect this page in .htaccess (or possible with only .htaccess)?
If is there anything more about 404 page let me know, I want to grab the knowledge.
And don't vote me down if possible of copy!
I want to map one error document file for 404 500 i am trying with this code.
ErrorDocument 404 /404.html
ErrorDocument 500 /404.html
RewriteEngine On
RewriteBase /
# map them to one error document:
RewriteCond %{REQUEST_URI} ^/404/$ [OR]
RewriteCond %{REQUEST_URI} ^/500/$
RewriteRule ^(.*)$ /404.html [L]
I tried this code and uploaded the file in main folder www.website.com/404.html
Its easier then I expected just gave full url:after reading documentation.and it worked.
ErrorDocument 404 http://www.website.com/404.html
ErrorDocument 500 http://www.website.com/404.html
No answer needed.
Where you want on your server
Yes : ErrorDocument 404 /yourPath/404.html
Google and Apache docs are your friends.
Edit : You add an image on your question. This is a 500 Internal Server Error, and not a 404 Page not Found error. Handle it with
ErrorDocument 500 /yourPath/500.html
But if your .htaccess file is corrupted and cause this error, you first have to fix your .htaccess file.
You can specify the document for error handling inside .htaccess similar to one below
ErrorDocument 404 /404.htm
This will override apache's default 404 page. The 404.htm will be inside your root folder.
https://www.addedbytes.com/articles/for-beginners/error-documents-for-beginners/
Related
My custom 404 error page only seems to work online for URLs that contain directories that don't exist. If I only have a non-existing file (in an existing directory tree), then I get - instead of my desired custom 404 page - a blank page with "File not found". Seems like, no matter if I have a non-existing file or an existing file in my URL, I only get my custom 404 page when there is a non-existing / misspelled directoy somewhere in the URL. Offline, on Xampp it works fine, though. Can anybody point me in the right direction as to what I might be doing wrong?
This is what my ".htaccess" looks like, which I put in my root directory along with my custom error page:
ErrorDocument 400 /error404.php
ErrorDocument 401 /error404.php
ErrorDocument 403 /error404.php
ErrorDocument 404 /error404.php
ErrorDocument 405 /error404.php
ErrorDocument 408 /error404.php
ErrorDocument 500 /error404.php
ErrorDocument 502 /error404.php
ErrorDocument 504 /error404.php
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,QSA]
</IfModule>
Update: It seems that the cause of my problems is the file extention ".php". If I call files that don't exist with an extention ".php" I get "File not found". If I use the extention ".html" in my query my custom 404 error page works alright.
example with html extention
example with php extention
Technial Support from my hosting provider suggests to have a look at my configuration where I include extentions. I am not sure where I should look to be honest. Maybe someone can narrow this down?
I have to further test this, but the following lines in my .htaccess file might do the trick:
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule ^.+\.php$ /non_existant_file
I have a custom 404 page called 404page.php , and I have the htaccess file with the line that I found should work (this is the only line I have in the .htaccess file)
ErrorDocument 404 /404page.php
It was working fine yesterday, but today I was optimizing images and some other stuff on the website, and when I reuploaded it, the htaccess didn't redirect to 404page.php anymore, but to a page that has this written:
Not Found
The requested URL /asfsdtg was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
(I just typed asfsdtg to test if it was working).
The website is uploaded online and I'm managing it through cpanel (I'm still a beginner). I searched for some solutions, I tried adding another line to .htaccess, then it looked like this:
RewriteEngine on
ErrorDocument 404 /404page.php
I even tried putting the location of the 404page.php as a local link, and the internet link, and it still gave me the weird error page.
Does anyone have some idea whats happening? If you need more info that I didn't supply please tell me what more I can supply
Try out this:
RewriteEngine on
ErrorDocument 404 http://yoursitename.com/404page.php
And be sure that 404page.php exists on the root of your server and is trully called 404page.php not 404Page.php
Be carefull at the characters, this is key sensitive!
Try with like this:
RewriteEngine on
ErrorDocument 404 http://www.sitename.com/404.php
Make to handle any 404 errors.
ErrorDocument 404 /404page.php
If above setting does not works you have to write addition line of code as mentions below.
Which identifies for non existing files and directories and redirect to 404.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ - [R=404,L]
I have a web app, and I want to redirect users to the 404 page without them actually ever going to a 404 page. Is this possible?
I added this line of code to my .htaccess file:
ErrorDocument 404 /404.php
So when a user types in (a page that does not exist on my website):
shareit.me/jsdhjfkhoe
They are redirected to:
shareit.me/404.php
Is there a way to redirect to the 404 while the URL remains:
shareit.me/jsdhjfkhoe
Use this to pass all paths to 404.php if they do not exist and preserve the URL:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /404.php [L]
Set this header in the 404.php file.
header("HTTP/1.0 404 Not Found");
This line:
ErrorDocument 404 /404.php
doesn't change the URL in the client browser since it does only internal rewrite to /404.php
I suspect you have some other rule in your .htaccess doing this full redirect. If you post your full .htaccess then I can investigate.
Actually this should do the trick:
ErrorDocument 404 /404.html
-> Try using an html element named 404.html in your root!
Have a look at this if you want to see a full implementation: https://github.com/h5bp/html5-boilerplate/blob/master/.htaccess
Otherwise you could have a look at the documentation if anything is unclear:
http://httpd.apache.org/docs/current/mod/core.html#errordocument
If you want to make your own customized Error 404 page. Here's what you need to write down on your .htaccess.
----------- .htaccess ----------------
# 1 ---- Establish a custom 404 File not Found page ----
ErrorDocument 404 /filenotfound.php
# 2 ---- Prevent directory file listing in all of your folders ----
IndexIgnore *
----------- .htaccess ----------------
Where filenotfound.php is your own 404 customized page. Hope it helped.
Please tell me why this is not working. It was working but has inexplicably decided to stop working.
In php I issue a 404 if the page is not found like so.
if(checkPageExists($escaped_url_page_name)){
header('HTTP/1.1: 200 OK');
}else{
header("HTTP/1.0 404 Not Found");
die;
}
My htaccess is
php_flag magic_quotes_gpc Off
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
ErrorDocument 404 /404.php
The 404 page is on the root and is name 404.php. Why would that not work when five minutes ago it was and nothing has changed. I have tested the page with fiddler and it is indeed throwing the 404's but the redirect is not happening. I have friendly urls implemented, but I would not think this affects it as the "/" in the htaccess refers to the physical root of the site I thought. Thanks in advance.
I had a similar issue once - when PHP throws a 404 header, Apache generally won't make a 404 page for it. (Edit: It probably has to do with whether PHP outputs any text. I haven't really experimented with it much.) If you check the headers in your browser, you can see that the 404 header worked, even if the page is blank.
I'm not sure about an automated solution, but I just made an http_error($code) function that prints my custom error page and called that along with header() whenever my code manually triggered a 404. Then I bound a bit of code to ErrorDocument that calls http_error only:
ErrorDocument 404 index.php?http_error=404
ErrorDocument 403 index.php?http_error=403
...and so on.
Please take a look at the following .htaccess
ErrorDocument 404 /404/
RewriteEngine On
RewriteRule (.*) index.php [L]
With this setup, I am using header('HTTP/1.1 404 Not Found'); in PHP to redirect to the error handling page and send the appropriate HTTP status code. The correct 404 status code is sent, but the browser shows a blank page and the access log shows "GET /invalid-url/ HTTP/1.1" 404 -
Can anyone tell me how to make ErrorDocument work with Apache URL rewrites?
Yes declare 404 document after the Rewrite rules
It's normal your server do not push any 404 error, you're using a catchall regexp ((.*)) as the only rewrite rule.
But your issue is not really htaccess related.
In php if you send 404 header the browser wont be redirected to the 404 page automaticaly, but you have to serve error page content yourself in PHP, as it is done by most frameworks with internal routing system.
I guess the answer to my question is: I don't need to.
What I was trying to accomplish was a "404 redirect". That is, when requesting an invalid URL, redirect to the 404 document along with setting the "Status 404 Not found" header.
And I am not sure that's something I want, because invalid URLs should be marked with the 404 status code, not redirected.
It should work if you define the Rewrite before the ErrorDocument.
Try this
ErrorDocument 404 /404.html
RewriteEngine On
RewriteRule (.*) index.php [L]