404 page returns 200 ok - .htaccess

If i type www.mydomain/error404.html directly in to browser bar should it return a 404 responce or 200 ok?
if i type www.mydomain.co.uk/something-that-dosent-exist.html, it returns the 404 page with the correct status as 404, however should my actual 404.html page return 200ok??
http://gsitecrawler.com/tools/Server-Status.aspx
domain http://www.novahealthy.co.uk
error doc error404.html
htaccess
AddType x-mapp-php4 .htm
#turn off the smart spelling matching feature.
CheckSpelling off
#set your real error document, which can be a php document.
ErrorDocument 404 /error404.html
host is 1and1 shared hosting
cheers for any help lee

Yes, that's correct. If you're going to any world-accessible site and your browser successfully gets that page you should have 200 OK returned.
Typically you don't keep error pages in a place that a user is able to directly access. You usually internally redirect to an error page on the server.

I would expect it to return a 200. Your page (even though it's named 404, and is being used as your redirect 404 page) exists, and it was found and served correctly.

Related

.htaccess, displaying 404 page without changing the user-entered url (no redirection)

So, my problem goes like this:
I created a custom 404 error page (error.html) and I want it to be displayed without actual redirection to the page, thus, keeping the user-entered URL. Examples:
User puts "http ://localhost/whatever.the.url/would/be" in their address bar.
error.html displays, but the URL in the address bar remains as entered by user: "http
://localhost/whatever.the.url/would/be"
I tried other people's guides and answers but they didn't work for me, perhaps because I'm really amateur and I have no idea how .htaccess actually works, sorry.
In addition to that, my .htaccess currently looks like this:
ErrorDocument 404 http://localhost/www.minimalistik.de/fejle/404/fejl.html/
Yeah it isn't much. Thanks to everyone who'd help me with this :)
To serve the error document via an internal subrequest (ie. the URL in the browser's address bar does not change) then simply specify a root-relative URL (starting with a slash) to your error document in the ErrorDocument directive (this is generally considered "normal" behaviour).
For example, if your error.html file is in the /error-documents subdirectory off the document root then you would use the following:
ErrorDocument 404 /error-documents/error.html
The user is not externally redirected to the error document.
ErrorDocument 404 http://localhost/www.minimalistik.de/fejle/404/fejl.html/
However, when you specify an absolute URL (ie. with scheme + hostname) as in this example then Apache triggers a 302 (temporary) redirect to the error document and the user is externally redirected. No "404 Not Found" response is returned to the client, unless the error document itself is returning a 404 status. And if it's returning a 200 OK (the default) then the error document itself could potentially be indexed by search engines! Needless to say, this is not recommended and is an error in most scenarios.
Reference:
https://httpd.apache.org/docs/2.4/mod/core.html#errordocument

403 redirects doesn't work but 404 does. What's wrong, what can I do?

First post around here !
I'm currently working on a website with Wamp and I am having an issue with 403 redirects. I would like to redirect all these 403 errors to a custom page.
In my .htaccess (the file is in www/project with my index.php) I have this two lines:
ErrorDocument 404 /project/views/error.php
ErrorDocument 403 /project/views/error.php
The thing is the 404 errors are perfectly redirected to the error.php page so it seems the path to the custom page is correct but it doesn't work for the 403 errors and still displays me the Apache default error page :
Forbidden
You don't have permission to access (a URL that return 403) on this server.
Please can you help me to understand what's happening because I really dont know why it doesn't work and I've seen lot of similar questions but no good answers yet.
Thank you

Is there a way to redirect without changing url?

I want to redirect my users to
www.spredt.com/404
But still having the url look the same as they typed it in the first place.
For example is someone entered www.spredt.com/93817218 and that page
doesn't exist in my directory it will redirect them but it will change
the url to www.spredt.com/404
I want the same /93817218 to stay unchanged in the url but still redirect them to the error document 404.
Right now I'm handling redirection with the .htaccess file.
ErrorDocument 500 https://www.spredt.com/500
ErrorDocument 404 https://www.spredt.com/404
ErrorDocument 403 https://www.spredt.com/403
But this changes the url.
I presume that you are redirecting your user in the 404 endpoint.
But you can just return the 404 page template when they enter a false url, and not redirect them.
The url will stay the same and they will see your 404 page.
I can't provide more detail because I don't have your code nor the langage.
EDIT :
In PHP you can do that to redirect and stay on the same URL :
include('http://www.spredt.com/404');
exit();
I can't test it right now, but it should work.
Source : https://bytes.com/topic/php/answers/545026-redirect-without-changing-address-your-browser

404 Redirect or better option

I have the following code in my htaccess file to handle 404 codes:
ErrorDocument 404 https://www.mywebsite.co.uk/lost.php
RewriteEngine On
And of course a custom 404 page is returned (works fine).
I did a nibbler check and it said the following:
It is a common mistake to setup missing page handling by using a
redirect. The missing page should directly return a 404 error and not
redirect to another page.
This website does not return a 404 error HTTP status code for missing
pages. This is bad because search engines like Google might mistake
this for a real page of content.
What is the best practice to handle 404 error codes if the above is no good? I am just wanting something generic that is a catch all. No need to use a 301 because the point of my 404 is just to let visitors know that what they are looking for is not there or they have made a typo.
If it is a "common mistake" to to use a redirect how should it be done?
Thank you for any help.
You need to remove https:// or http:// from 404 handler otherwise it forces Apache to do a full redirect instead of internal rewrite.
So you can use:
ErrorDocument 404 /lost.php
It depends. If you have an application running on the webserver that takes in every URL coming in and has some logic implemented, that by itself has to figure out if the URL exists, then the application should directly return a 404 error page under the given URL and not redirect to another page like 404.html or so. But if your webserver handles the url requests with the .htaccess file then it is OK to setup a document that is returned in case of an invalid URL.

Google URL errors - soft 404s.

I've recently restructured my site and in the process have removed many pages.
I've put in .htaccess 301 redirects to reflect the changed structure where new pages directly replace old pages; have put in a custom 404 page and have included the following .htaccess command: ErrorDocument 404 /page-not-found.html.
For pages removed altogether that have no new equivalent page, I've used .htaccess to redirect to the 'page not found' custom page.
In webmaster tools, though, I'm seeing soft 404s reported - pages not found that are not returning 404 response codes.
Can anybody please advise a way forward on this?
Should I not redirect references to the deleted pages and let the 'pages not found' stack up in the webmaster tools report, or is there a way of returning a 404 code from the server for my deleted pages even though a redirect exists?
Any advice would be much appreciated.
Thanks,
Andrew
I think if the page doesn't have a new equivalent, then let it fall through not found, and return a 404 (which should show your custom page).
Google is showing a soft 404 because of the redirect (which is a 301, not a 404), as you say.
If you did redirect to the custom page, and somehow returned a 404, that's essentially the same thing as just letting them not be found.
The pages not found will stack up, but if they really aren't found anymore, then that's the correct response.
The alternative would be a 301 to a different page, that was a real "hey this moved, try this instead" page, but it would have to look like something other than "not found", to avoid google treating it as a soft 404.

Resources