Forum Moderators: phranque

Message Too Old, No Replies

.htaccess to issue a 404 error for all requests

         

classifieds

1:19 am on Mar 8, 2006 (gmt 0)

10+ Year Member



I moved a site last year from one hosting company to another. The old host did not delete the account or the script.

G, Y and Jeeves all continued crawling the server using its IP address which has resulted in a large number of duplicate pages in their indexes where the urls looks like [128.0.0.0...] but the contents of the page are the same as www.mydomain.com/page-name.html .

The host has given me access to the server and I need to upload an .htaccess file that will generate a 404 error for every request.

I’ve read everything I can find on .htaccess and I can’t figure out what commands to use.

Any help would be appreciated.

msr986

1:36 am on Mar 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Now that you have access, why don't you just delete your files off of the old server? I don't think I would want to leave old html files laying around. Just a thought.

classifieds

2:24 am on Mar 8, 2006 (gmt 0)

10+ Year Member



I left out some information. Sorry. . .

I've already deleted the app/files and all references to them are returning 404s.

I'm now trying to get 128.0.0.0/ to return a 404.

extras

5:56 am on Mar 8, 2006 (gmt 0)

10+ Year Member



1. You can use asis document to send out any response code.
2. You can use cgi (amd probably php) for that, as well.
3. You can use RewriteRule and rewrite to a bogus filepath,
but the default 404 page may show the bogus path.

So, I'd go for the method #1 or #2.

#1
In the .htaccess, you put these.
AddHandler send-as-is .asis
DirectoryIndex index.asis

Then, create the asis document, index.asis:


Status: 404 Not found
Content-type: text/html

<html><body>
<h1>Error 404 Not Found</h1>
</body></html>


Make sure that "Status" line is the very first line in the file.
And you need that blank line after Content-type: header
(or at the end of response header).

Other than that, you can edit and send anything valid you want.

#2
In the .htaccess, you need to put these
DirectoryIndex index.cgi

Then you need to have index.cgi with executable permission 700 (or 755 may do).


#!/bin/sh
echo 'Status: 404 Not found
Content-type: text/html

<html><body>
<h1>Error 404 Not Found</h1>
</body></html>'

Basically you need to send the same thing as the asis document.
The advantage of using cgi is you can do other things, such as taking log or sending mail or whatever you want.
But if you do heavy thing, you may tax the server.

asis <== the simplest and lightest way.
cgi (or other dynamic method) <== you can do many things

Probably, there are other ways, too.

classifieds

9:15 am on Mar 8, 2006 (gmt 0)

10+ Year Member



Thanks Extras!

I hacked at .htaccess for sometime and then I realized . . .

I just needed create an index.php with this in it:

<?
header("HTTP/1.0 404 Not Found");
?>

It seems to work fine :)

extras

4:50 pm on Mar 8, 2006 (gmt 0)

10+ Year Member



Good for you.
If the server is using mod_php, I think it's a good choice.

If the PHP is running as cgi, it's a bit heavy.
But it shouldn't matter for small traffic.