homepage Welcome to WebmasterWorld Guest from 54.234.147.84
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
301 redirect of php page on Windows host
How will search engines see it?
kiwibrit




msg:4041646
 8:57 pm on Dec 11, 2009 (gmt 0)

I have a php site operating a Windows web host (there are good reasons - going to an Apache server is not an option). I do not have access to IIS via the site's control panel - and of course .htaccess will not work.

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?

 

TheMadScientist




msg:4041651
 9:10 pm on Dec 11, 2009 (gmt 0)

I haven't ever had a problem with what you are suggesting...

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.

kiwibrit




msg:4041721
 11:16 pm on Dec 11, 2009 (gmt 0)

Thanks very much. Maybe it's best to use the full url (such as http://www.example.com/index.php) for an index page as one would for other non-index pages (such as http://www.example.com/widgets/brown.php)?

TheMadScientist




msg:4041758
 1:28 am on Dec 12, 2009 (gmt 0)

It really depends on if you are redirecting index.ext requests to the root directory to prevent duplicate content issues.

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.

kiwibrit




msg:4042136
 12:03 am on Dec 13, 2009 (gmt 0)

Hmm. Thanks for the tip on checking with the control panel - both there and elsewhere I am getting a 302 re-direct, rather than the desired 301 showing.

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?

TheMadScientist




msg:4042149
 1:04 am on Dec 13, 2009 (gmt 0)

Hmmmm...

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.

kiwibrit




msg:4042271
 11:43 am on Dec 13, 2009 (gmt 0)

Here's the results of my test:


<?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';
}
?>

Results in the word 'problem' being rendered on the screen.
However, the control panel also shows a 301 redirect status - albeit that no header location has been set.


<?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?

kiwibrit




msg:4042282
 12:44 pm on Dec 13, 2009 (gmt 0)

Supplementary note - the web host server can also run asp.net - so I ran a test on the aspx equivalent

<%@ 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.

Nutter




msg:4042346
 4:09 pm on Dec 13, 2009 (gmt 0)

I had something similar happen with an exit() right under the headers. Don't remember if it was IIS or not, and have no clue why, but it caused some issue with the redirect. Either without the exit() or with exit("Something here") it would send the 301 header.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved