Forum Moderators: coopster
Setting up a 301 redirect is therefore a problem.
<? php
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.example.com" );
?> Would re-direct. I can't see a problem for search engines - or is there something I have not thought of?
I use Apache Servers, but platform should not matter. The only thing that really matters is serving a proper 301 redirect and it looks like you've got it. There are cases where I use PHP instead of Mod_Rewrite for simplicity and have not had any issues.
Always make sure you double check your server headers (you can do it here in the control panel) and as long as you are serving a 301 redirect you should be fine...
The only changes I would suggests are:
header() - Lower Case H
http://www.example.com/ - Trailing /, because otherwise there will be 'chained' or 'stacked' redirects which are known to not pass link weight. The reason they will be 'stacked' is there will be one redirect from your script to http://www.example.com and another by your server to http://www.example.com/ (2 x redirects) which is undesired, so make sure you take them to the correct location the first time and don't force your server to redirect again for the visitors (or search engines) to get to the correct location.
The best practice I know of is to make sure you redirect to exactly where you want the visitor (person and bot) to end up with the redirect you put in place with your PHP. It does not really matter what the URL is... Just get them there with a single redirect.
The full report is:
HTTP/1.1 302 Redirect
Content-Type: text/html; charset=UTF-8
Location: http://www.example.com/widget/index.php
Server: Microsoft-IIS/7.0
X-Powered-By: PHP/5.2.9-1
X-Powered-By: ASP.NET
Date: Sun, 13 Dec 2009 00:00:37 GMT
Connection: keep-alive
Content-Length: 167
Connection: keep-alive
Content-Length: 158
Any thoughts on why it is showing as a 302?
Glad you checked.
What's the exact code you are using?
It looks like only the redirect header is being sent for some reason...
You might want to have a look at headers_sent() [us3.php.net] and trouble shoot from there if you're relatively sure your code is correct to set the 301 header. The related links might also be helpful to you.
<?php
header("Location: http://www.example.co.uk/");
if (!headers_sent()) {
echo 'problem';
}
?>
Results in a redirect - detected as a 302 by the control panel.
<?php
header("HTTP/1.1 301 Moved Permanently");
if (!headers_sent()) {
echo 'problem';
}
?>
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.co.uk/");
exit();
?>
results in the page for example.co.uk/ being rendered - but the control panel once more shows a 302 redirect - as shown below:
HTTP/1.1 302 Redirect
Content-Type: text/html; charset=UTF-8
Location: http://www.example.co.uk/
Server: Microsoft-IIS/7.0
X-Powered-By: PHP/5.2.9-1
X-Powered-By: ASP.NET
Date: Sun, 13 Dec 2009 11:37:19 GMT
Connection: keep-alive
Content-Length: 144
I am beginning to think that the web host IIS 7 has a bug in that it is handling only the latest header sent to it - so that the status of the 301 redirect reverts to a default mode of 302 when it has to cope with a location header instruction. Would you agree?
<%@ Page Language="C#" %>
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.example.co.uk/");
}
</script> It worked fine - with redirection working - and a 301 redirect showing in the webmasterworld control panel.