Welcome Guest, Not a member yet? Register   Sign In
Sending 404 status code with error page
#1

[eluser]david_ais[/eluser]
I have discovered that the 404 error page returned by CI is returned with a status code of 200 instead of 404.

That might seem like a minor point. But it means for example that the error page will get index by Google instead of being ignored at it would if it the correct status code had been returned.

Can anyone suggest how to arrange to return a 404 error code with the error page instead of the default 200 status code?

Regards

db
#2

[eluser]Derek Allard[/eluser]
Its because everything runs through index.php, so technically it was found. The solution is htaccess. There's some great help on the ExpressionEngine wiki at http://expressionengine.com/wiki/Remove_...From_URLs/. Look down for the note on "Important note for SEO" about half way.
#3

[eluser]david_ais[/eluser]
[quote author="Derek Allard" date="1194379211"]Its because everything runs through index.php, so technically it was found. The solution is htaccess.[/quote]

That makes sense. The resource you listed gives some useful background but unfortunately nothing that gets me any further forwards. It did however confirm my fears that this problem will give rise to duplicate content as far as a search engine is concerned.

I'm currently using mod_rewrite to map out the index.php from the URL. So that means pretty much everything gets passed to CI anyway. Which as you say means the CI page is always found. If CI can't then generate a page it spits out the error page. I guess what I was hoping for is the possibility that somehow CI might be able to send a 404 status code along with the error page.

I don't understand how .htaccess helps in this case. Can you explain further how I could use .htaccess in this situation? Alternatively - might a mod to CI be possible to send a different status code? If so can you give me any hints as to how to approach it?

Regards

db
#4

[eluser]Pygon[/eluser]
You might try http://valet.seoconsultants.com/ to see what response is sent.
#5

[eluser]david_ais[/eluser]
[quote author="Pygon" date="1194386286"]You might try http://valet.seoconsultants.com/ to see what response is sent.[/quote]

I know what status code is returned - I can see it in the server access log. It's 200 whereas if it's for a page not found error page it should be 404

Regards

db
#6

[eluser]Pygon[/eluser]
Nevermind -- I've just been able to track these issues before using it, but since the seperate error page isn't actually loading, maybe it won't help much.

Looking in my access logs, 404 is being sent.

Are you using a custom error_404.php?
#7

[eluser]david_ais[/eluser]
[quote author="Pygon" date="1194389619"]Nevermind -- I've just been able to track these issues before using it, but since the seperate error page isn't actually loading, maybe it won't help much.

Looking in my access logs, 404 is being sent.

Are you using a custom error_404.php?[/quote]

The page that's listed in the server access log is whatever page was requested. As Derek said, because index.php is running and returns an output, a 200 status code is returned. In the absence of another page to display CI just returns the contents of /application/errors/error_404.php - which I've customized. Not that it would make any difference as CI just echos the contents to the output.

Although CI's own log records it as a 404 page error - in the server log it's listed with status 200. If you're seeing 404 there - tell me how you did it! I don't see anywhere in CI that's sending status headers. Or did I miss something?

Regards

db
#8

[eluser]Pygon[/eluser]
I would suspect that you've possibly removed the first line of the error_404.php in application/errors/error_404.php

which is:
Code:
<?php header("HTTP/1.1 404 Not Found); ?>
#9

[eluser]david_ais[/eluser]
[quote author="Pygon" date="1194407802"]I would suspect that you've possibly removed the first line of the error_404.php in application/errors/error_404.php

which is:
Code:
<?php header("HTTP/1.1 404 Not Found); ?>
[/quote]

Ooops - you're absolutely right. Re-inserted the line and it works fine now!

It's soooo embarrassing when it turns out I did something as dumb as that. Thank's everyone for your input!

Regards

db
#10

[eluser]Derek Allard[/eluser]
Oh boy, glad you caught it... I have to admit I was looking at the code and thought "oh man... another thing to dig into". I'm glad it turned out to be simple , and thanks pygon for saving me work! Smile




Theme © iAndrew 2016 - Forum software by © MyBB