-1

I am trying to redirect a page using HTTP 410 status using php header function as

header("HTTP/1.1 410 Gone");
header('Location: http://domain.com/down.php');
exit;

The problem is that even if I set a 410 status code...the status code will automatically change to 302

I have also tried with

header('Location: domain.com/down.php', true, 410);
exit;

It shows 410 redirection but the redirected page does not show anything. It shows a blank page.

Does anybody know if there is a solution for this?

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Nilesh
  • 1,047
  • 1
  • 12
  • 20
  • Can you say what you're trying to do? Do you want to create a redirect or do you want to give a "Gone" message (which is *not* a redirect, but an error). – hakre Sep 28 '11 at 10:30
  • I want to redirect to a page where I can show some message to user about site maintenance. – Nilesh Sep 28 '11 at 10:47
  • Try: `header("HTTP/1.1 503"); include('path/to/down.php'); exit;` - you are definitely **not** looking for a redirect, nor for a 410 gone message for site maintenance. See vsushkov's comments as well. Just use the right tool for the job, you can't change HTTP because you just want to. – hakre Sep 28 '11 at 10:49

5 Answers5

8

The 410 error indicates that the Web server has no forwarding address for the URL, so can provide no redirection to the new Web server. So the blank page you got using the second snippet is correct. The first code snippet also gives the correct result - Location creates a redirect to a given address. So there is no errors in your code or in PHP. I'm not sure you do what you realy need =)

vsushkov
  • 2,445
  • 1
  • 19
  • 28
  • I want to redirect all my pages with HTTP 410 status to maintenance page when my site is in Maintenance mode. – Nilesh Sep 28 '11 at 10:30
  • 5
    maintenance is not a client error. It's a server-side stuff. So you need one of 5xx codes. Namely, 503 Service Unavailable – vsushkov Sep 28 '11 at 10:34
1

The last header line is a correct way to set the status code:

header('Location: domain.com/down.php', true, 410);

However, the Location header name requires a fully qualified URL, your URL looks incomplete. That's not valid.

Next to that you don't send any HTTP response body, so the browser can only display a blank page. To display a non-blank page, provide a response body:

header('Location: http://domain.com/down.php', true, 410);
echo '<h1>Gone.</h1><a href="http://domain.com/down.php">here.</a>';
exit;

Providing a response body is useful, because user-agents do not need to follow Location headers automatically, especially as with the 410 response code RFC 2616, no response header named Location is expected by a HTTP client.

Maybe you're looking for 301 Moved Permanently.

hakre
  • 193,403
  • 52
  • 435
  • 836
1
header('Location: http://domain.com/down.php', true, 410);
exit;

Should works. You forgot about protocol in URL.
Besides, AFAIU, Yo can use

header('Location: 'http://domain.com/'down.php');
header("HTTP/1.1 410 Gone");
exit;

But Are you sure you need Redirect and 4xx HTTP status?

RiaD
  • 46,822
  • 11
  • 79
  • 123
0

You have to include the error page :

header("HTTP/1.0 410 Gone"); include_once("410.html"); exit();
0

Try to use some proper quotes?

header("HTTP/1.1 410 Gone");
header("Location: http://domain.com/down.php");
exit;
Michiel
  • 7,855
  • 16
  • 61
  • 113