views:

290

answers:

5

I have been googling for this but no one appears to have the answer.

This post describes the problem well:

http://www.mail-archive.com/[email protected]/msg198576.html

Server is Windows 2008 FastCGI PHP 5

Anyone solved this problem?

A: 

I don't have PHP here to test this, but wouldn't this produce a 301?

header('Location: http://www.example.com/', true, 301);
R. Bemrose
You would think so but no, it produces a 302 redirect
Paul
I would be tempted to delete this answer, but I think it'd be better to leave it here so someone else doesn't suggest the same thing.
R. Bemrose
A: 

It should be as given by R. Bemrose; that's the usual example code. I guess there is something not-quite-right about your PHP execution environment.

Another method you can try is the CGI standard way of passing back a status line:

header('Status: 301 Moved permanently');
header('Location: http://www.example.com/');
bobince
That should work, and I would expect it to, but it's just not. I read that it might be a bug in the FastCGI module, but I can't find anything to fix it.
Paul
+1  A: 

It appears that the only answer to this one at the moment is to not use FastCGI on IIS7 when using PHP (because of a bug in FastCGI) - which is rubbish because it's very quick. Using isapi allows the 301 redirects to work as they should, but it's not as fast.

Paul
A: 

Although not an answer, I thought it might be worth adding that I have a similar issue of getting a 302 instead of a 301, despite the coded status being set as 301 (using VB.Net). I should add that I'm using a custom "404" page to determine if the page really is not found, or if it is listed in our data table of historical redirects.

Me.Response.Status = "301 Moved Permanently"
Me.Response.AppendHeader("Location", rootPath + NewPage)

The rootPath and NewPage variables are obtained from Request.ServerVariables and a SQL database table respectively. Using the nicely detailed HTML analysis viewer from http://www.rexswain.com/httpview.html

the server sends a sequence of status codes as: 302 (the custom 404+301 page handler), then 301, then 200 (the page redirected to).

I've not found anyone suggesting an alternative code method. The best result seems to be manually configuring each 301 in the IIS management console, but this requires that the original file remains on the server, which ain't great.