ErrorDocument 404 just shows "404" - php

I have setted up my .htaccess with some bundles of rewrites, although when I go to an invalid directory which the ErrorDocument 404 is already set up, it just shows "404" on the page, nothing else, just a plain text with "404".
RewriteEngine on
RewriteBase /
RewriteRule ^404/?$ 404.php
ErrorDocument 404 404
Why doesn't it show the 404 page, if I go to 404.php or http://www.mydomain.com/404 it shows just fine, why won't it show the page?

You need to reformat your .htaccess, see:
http://www.javascriptkit.com/howto/htaccess2.shtml
The correct line is:
ErrorDocument 404 /errors/notfound.html

Related

Why is custom 404 PHP error page only working online for URLs where non-existing directories are involved, no matter if the file exists or not?

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

Why can i go to www.domain.com/index.php/put_anything_here?

Why is it possible to go further into my index.php file as it was a folder like: www.domain.com/index.php/put_anything_here_and_it_loads_the_file_without_styling
I want it to use the .htaccess to redirect them to the index.php when they go to a file that does not exist like index.php/anything_here - but for some reason it thinks that index.php/anything_here exists...
Right now i have just set my .htaccess to redirect to this page if one of the errors happen:
This is my .htaccess:
ErrorDocument 404 /404error.php
ErrorDocument 400 /404error.php
ErrorDocument 401 /404error.php
ErrorDocument 403 /404error.php
ErrorDocument 500 /404error.php
Thanks

How 404 page will work

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/

000webhost.com Custom Error page does not work?

When i change the code and add something new it doesnt even lets me load my normal page. If delete the ErrorDocument 404/error.php(and the others) I can normally enter my site.
Here is my sites domain: carnageband.tk
Here is the code:
# Do not remove this line, otherwise mod_rewrite rules will stop working
RewriteBase /
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php
What should i do to bypass the page which it redirects me? LINK
I just had the same problem and the issue seemed to be coming from the .htacess file. The webpage would load okay again after I deleted the .htaccess file.
I was able to fix it by editing the .htaccess file from the cPanel, File Manager instead of transferring the file over FTP, but I'm not really sure why it wasn't working before.
My code looks similar to yours:
# Do not remove this line, otherwise mod_rewrite rules will stop working
RewriteBase /
ErrorDocument 403 /errors.php?p=403
ErrorDocument 404 /errors.php?p=404
ErrorDocument 500 /errors.php?p=500

.htaccess not redirecting to 404.php instead shows page name

Am trying to make a custom 404 page for my website and am having .htaccess file in the root directory where am using this rule
ErrorDocument 404 404.php //I want to redirect to 404
So when I change a valid file name like home.php to home1.php it doesn't redirect me instead it echo's 404.php on that page
Side Note: 404.php is in the root directory only
This should do it
RewriteEngine on
ErrorDocument 404 http://www.yoursite.com/404.php
In your .htaccess file, you should be able to use:
RewriteEngine on
ErrorDocument 404 /404.php
You can set additional error documents using this method, but I'd put them in a separate errors directory:
ErrorDocument 400 /errors/400.php
ErrorDocument 401 /errors/401.php
ErrorDocument 403 /errors/403.php
ErrorDocument 404 /errors/404.php
ErrorDocument 500 /errors/500.php
you could do the following to 404 old pages with your htaccess
RewriteEngine on
ErrorDocument 404 /404.php
but i would personally recommend
RewriteEngine on
RewriteRule home.php /home1.php [R=301,L]
as this would do a 301 redirect from the old page name to the new page name, so any cached search engine results would still end up at the correct page instead of hitting a 404
In my case, using an Ubuntu distribution, the directive ErrorDocument has no effect if it is in the .htaccess in htdocs directory or elsewhere: it turned out that it should be put in the proper /etc/apache/sites-enabled/*.conf file, inside the <VirtualServer> directive (for example, if the website is providing https pages, inside the directive <VirtualHost *:443>).

Categories