Jump to content

Recommended Posts

Correct me if I'm wrong, but I don't think browsers have default 404 error pages. Servers might, but browsers...no, I don't think so.

 

You should be able to create your own 404 pages if you would like, or display different ones depending on browser type.

Well whenever I get a 404 error, it displays the same thing every time unless they have a custom 404 page on the site.

 

Try typing in something like "936534bv78049bq94.b9v3w5y"

in your address bar and then "njmkrzy3a689w3.9n4860wv34"

 

It displays the same 404 error message on both pages. But on different browser they are different.

 

 

Edit: Oh lol, oops I guess there is no one for browsers, well how would you get the default 404 error of the server?

When you say, "I get a 404 error", are you talking about on your site or just Web sites in general?

 

Are you sure these are 404 sites and not "server not found" sort of pages? For example, if you go to a page on a working Web site that does not exist (such as http://www.yahoo.com/asdf/asdf/asdf), you should get that site's 404 error page. However, if you visit a site on a server that does not exist (such as www.thissiteissocoolandthenameisverylongthatmakesitacoolsite.com), you will probably get some sort of "server not found" error, which varies in appearance from browser to browser (it also appears that DNS settings can affect how this appears as well. I have OpenDNS set up on my network, so instead of my browsers' error pages, I get pages that are from OpenDNS).

 

EDIT: I apologize. I wrote this reply before you edited your post, so I did not get to see it.

 

Whenever you try to visit a page on a Web site that does not exist, you should automatically get a 404 error from the site. If the Web site does not have a custom one specified, you usually get a plain "404 Not Found, /whateveryoutriedtorequest was not found on this server"-type of page.

Make sure you aren't echo'ing anything before this, but the following will force a browser to think it is a non-existent page (404 error)

 

header("HTTP/1.0 404 Not Found"); 
exit;

 

a side note: this will force a browser specific 404 (each browser's 404 error page will look different) - if you want to provide a custom 404 look (a default 404 for your whole site) you need to include/print the page before the exit call

I have tried using header("HTTP/1.0 404 Not Found") before I posted here. I will show my code.

 

<?php
$password = $_POST['password'];
if ($password != "TEST") {
	header("HTTP/1.0 404 Not Found");
} else {
	$name = $_POST["name"];
	echo "&name=" . $name;
}
?> 

a side note: this will force a browser specific 404 (each browser's 404 error page will look different) - if you want to provide a custom 404 look (a default 404 for your whole site) you need to include/print the page before the exit call

 

Firefox will show the response headers a 404, but you need to show a 404 page otherwise it will be blank. I should have mentioned that earlier, sorry. As for the other part of the question, read the above quote from earlier.

Well I will just redirect it to a non-existing page for now because it displays my websites 404 error message.

By doing that, you're showing the user you didn't want them to see that something 'valuable' is at the location they just tried to visit, but hey... it's your site ;)

Well I will just redirect it to a non-existing page for now because it displays my websites 404 error message.

If you still want to "hide" your files that you dont want people to see, make your 404 document redirect to a 404 file, like your .htaccess file directs to 404.php wich redirects to 404.html...

 

Then on the password protected pages, redirect to the 404.html file as well? (or 404.php, if you have any intrest of that.)

I decided to redirect it to a 404 page I just made. This is for the people that want to do that same thing as I wanted to and don't know how to redirect it to a custom page.

 

First go to your website and enter a page that doesn't exist, such as www.yourwebsite.com/thispagedoesnotexist

 

A 404 error will pop up, then open a new tab or window and go to www.thisisnotawebsite.nothing

 

If the same error pops up then you will have to make your own 404 error page, if it is different right click the page of "www.yourwebsite.com/thispagedoesnotexist" and look for something like view source, view info, source... click on it and then copy the code that appears, then create page on your website called 404Error.html and paste in the code that you copied. That is just to make it look more like the other error pages your server displays.

 

Now open the .htaccess file in your website and put in

 

ErrorDocument 404 http://www.yourwebsite.com/404Error.html

 

at the end of the file.

 

If you have something like Dreamweaver to create your website you may be wondering "Where is the .htaccess file?". Well it is on your website so go into remote view and you will find it, then download it. If you can't find it at all just create a new file called .htaccess and put the code I gave you above into it.

 

If something bad happens to your website if you create a new .htaccess file it is not my fault, it means it was on your website the whole time and you couldn't find it.

 

 

 

Once you got that all set up use the code

 

header("Location: /404Error.html");
exit;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.