Welcome to WebmasterWorld Guest from 54.224.96.57

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Problem with creating 301 redirect

Server producing 302 redirect instead

     
12:05 am on Jul 30, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 12, 2004
posts:961
votes: 0


For PHP pages that have moved, I need to permanently redirect users to new pages. That should be simple: Just return a 301 "Moved Permanently" status code via PHP's header command. However, my server oddly returns a 302 status instead.

I have PHP 4.3.6 running on IIS 6.0 (Windows 2003 Server) and have introduced the following PHP code:

<?php
header('HTTP/1.1 301 Moved Permanently');
header('Location: [example.com...]
exit();
?>

This is a textbook example, repeated ad nauseum on the web, so it should work. I've tried a number of variations, as well. But my server is always returning a 302 status instead. For all of you who know about search engine optimization, you know what a problem that can be.

There appears to have been a bug in PHP 4.3.0 that caused this exact problem - the "Location" header would always mistakenly returned a 302 no matter what the code specified. It was supposedly fixed in 4.3.3. However, I've got 4.3.6 and it's doing the same thing.

Any ideas on how to solve this?

12:25 am on July 30, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 22, 2002
posts:2546
votes: 0


You may want to try sending the Status header by itself.

<?php
header('Status: 301 Moved Permanently');
header('Location: ht*p://www.example.com/newurl.html');
exit();
?>

12:37 am on July 30, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 12, 2004
posts:961
votes: 0


Birdman,

Great suggestion. Done that already. Didn't work.

4:17 am on July 30, 2004 (gmt 0)

New User

10+ Year Member

joined:July 22, 2004
posts:31
votes: 0


what about the .htaccess file?

Do you use a "ErrorPage 404 /myscript.php"?

4:43 am on July 30, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 12, 2004
posts:961
votes: 0


I use IIS from Windows Server 2003. Therefore, there is no .htaccess file.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members