Forum Moderators: phranque

Message Too Old, No Replies

Setting Headers

Headers: 404 showing as 200 not 404

         

hunkydory

9:16 am on Aug 30, 2005 (gmt 0)

10+ Year Member



Hello,

I was wondering if anyone could help, for SEO reasons I need to show my 404 errors as 404 in the page header not 200 as my server currently shows them. I assume this has to be done with .htaccess?

At present my .htaccess has:

Redirect permanent /links1.htm [domain.com...]
Redirect permanent /links2.htm [domain.com...]

RewriteEngine on

RewriteCond %{HTTP_USER_AGENT} Wget [OR]
RewriteCond %{HTTP_USER_AGENT} CherryPickerSE [OR]
RewriteCond %{HTTP_USER_AGENT} CherryPickerElite [OR]
RewriteCond %{HTTP_USER_AGENT} EmailCollector [OR]
RewriteCond %{HTTP_USER_AGENT} EmailSiphon [OR]
RewriteCond %{HTTP_USER_AGENT} EmailWolf [OR]
RewriteCond %{HTTP_USER_AGENT} ExtractorPro
RewriteRule ^.*$ [domain.com...] [L]

ErrorDocument 400 [domain.com...]
ErrorDocument 401 [domain.com...]
ErrorDocument 404 [domain.com...]
ErrorDocument 500 [domain.com...]

Any ideas?

Thanks

Henry

Longhaired Genius

9:33 am on Aug 30, 2005 (gmt 0)

10+ Year Member



RewriteRule ^.* - [F,L]

"F" for forbidden!

hunkydory

9:44 am on Aug 30, 2005 (gmt 0)

10+ Year Member



so add the rule:

RewriteRule ^.* - [F,L]

or append it to my current Rewrites?

Thx

Longhaired Genius

9:55 am on Aug 30, 2005 (gmt 0)

10+ Year Member



Replace your RewriteRule.

(Can't hurt to add the final delimiter...)

RewriteRule ^.*$ - [F,L]

hunkydory

9:58 am on Aug 30, 2005 (gmt 0)

10+ Year Member



Thanks will give it a go now

hunkydory

10:03 am on Aug 30, 2005 (gmt 0)

10+ Year Member



Still get the header as 200 not 404, adjusted as said:

Redirect permanent /links1.htm [domain.com...]
Redirect permanent /links2.htm [domain.com...]

RewriteEngine on

RewriteCond %{HTTP_USER_AGENT} Wget [OR]
RewriteCond %{HTTP_USER_AGENT} CherryPickerSE [OR]
RewriteCond %{HTTP_USER_AGENT} CherryPickerElite [OR]
RewriteCond %{HTTP_USER_AGENT} EmailCollector [OR]
RewriteCond %{HTTP_USER_AGENT} EmailSiphon [OR]
RewriteCond %{HTTP_USER_AGENT} EmailWolf [OR]
RewriteCond %{HTTP_USER_AGENT} ExtractorPro
RewriteRule ^.*$ [domain.com...] [F,L]

ErrorDocument 400 [domain.com...]
ErrorDocument 401 [domain.com...]
ErrorDocument 404 [domain.com...]
ErrorDocument 500 [domain.com...]

Longhaired Genius

10:05 am on Aug 30, 2005 (gmt 0)

10+ Year Member



The rule should be literally this:

RewriteRule ^.*$ - [F,L]

"F" means load the error document. You don't need to reference it twice.

Also, the error documents should be linked relatively from thr RewriteBase (probably "/"), not absolutely (with [)....]

hunkydory

10:20 am on Aug 30, 2005 (gmt 0)

10+ Year Member



Okays have now adjusted and added the rewrite base:

RewriteEngine on

RewriteCond %{HTTP_USER_AGENT} Wget [OR]
RewriteCond %{HTTP_USER_AGENT} CherryPickerSE [OR]
RewriteCond %{HTTP_USER_AGENT} CherryPickerElite [OR]
RewriteCond %{HTTP_USER_AGENT} EmailCollector [OR]
RewriteCond %{HTTP_USER_AGENT} EmailSiphon [OR]
RewriteCond %{HTTP_USER_AGENT} EmailWolf [OR]
RewriteCond %{HTTP_USER_AGENT} ExtractorPro
RewriteRule ^.*$ - [F,L]

RewriteBase /

ErrorDocument 400
/notfound.htm
ErrorDocument 401
/notfound.htm
ErrorDocument 404
/notfound.htm
ErrorDocument 500
/notfound.htm

Yet the entire site now gives a 500 internal server error, sorry about this.

Thanks
Henry

Longhaired Genius

10:28 am on Aug 30, 2005 (gmt 0)

10+ Year Member



You don't need to explicitly state the RewriteBase if the .htaccess file is in the root directory but if you do, put it at the top with RewriteEngine on.

The error documents should be referenced like this:

ErrorDocument 400 /notfound.htm

(Each one on one line.)

encyclo

10:31 am on Aug 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ErrorDocument 404 http://www.example.com/notfound.htm 

The answer is simple - you must not use an absolute link for the 404 page, otherwise it is seen an external file, so called giving a 200 OK. Use this:

ErrorDocument 404 /notfound.htm

hunkydory

10:34 am on Aug 30, 2005 (gmt 0)

10+ Year Member



Thanks all working now, i really appreciate your help!