Welcome to WebmasterWorld Guest from 54.162.240.235

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)

WebmasterWorld Senior Member 10+ Year Member



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 Jul 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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 Jul 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Birdman,

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

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

10+ Year Member



what about the .htaccess file?

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

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

WebmasterWorld Senior Member 10+ Year Member



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

Featured Threads

Hot Threads This Week

Hot Threads This Month