• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1977
  • Last Modified:

Sending 410 status code with redirect?

I have a 404.php file on my website to take care of my file not found errors. The default procedure (if not specified otherwise) is to forward the user to my main page AND I also want to send a 410 status code so that search engines that are following an incorrect URL don't think I'm cheating and using multiple doorways to point to my main page.

The problem ist that even if I send a 410 status code before...

header ("HTTP/1.0 410 Gone");

...the status code will automatically change to 302 as soon as I forward to a different page (as specified in the PHP manual: http://www.php.net/manual/en/function.header.php).

header("Location: http://www.mydomain.com/");

Does anybody know if there is a solution for this?

Thanks!
0
yosmc
Asked:
yosmc
  • 3
  • 2
1 Solution
 
3ggCommented:
410 Gone shouldn't re-direct! If you want moved, you would want 301 or 302.
0
 
yosmcAuthor Commented:
Let me try again...

I am currently using the following two lines in my 404.php file:

header ("HTTP/1.0 410 Gone");
header("Location: http://www.mydomain.com/");

My problem is that the second line will overrule the first line. Instead of a 410 gone status code, it will send a 302 moved status code. However, I don't want to send a 302!

Hope that's clearer. :)
0
 
3ggCommented:
Yes, your code is clear, however, to re-direct the browser you would need to use the 302 code instead. You might consider trying a meta re-direct instead, you will be able to keep your error code that way, but still accomplish the same effect.

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
yosmcAuthor Commented:
The problem is that search engines HATE meta-redirects, and Google even gives penalties for them...
0
 
yosmcAuthor Commented:
In the meantime I was able to solve this problem. Basically, if a 404 file ends up sending a 302 header, it's a good idea to double- and triple-check if the file itself doesn't contain code that accidentially sends the header. (In my case, I had a META-tag somewhere that I deemed harmless - but after removing it, I finally got the 4xx header I desired.) Hope this helps someone.
0
 
PashaModCommented:
Question closed and points refunded

PashaMod
CS Moderator
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now