homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Problem with creating 301 redirect
Server producing 302 redirect instead

 12:05 am on Jul 30, 2004 (gmt 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:

header('HTTP/1.1 301 Moved Permanently');
header('Location: [example.com...]

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)

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

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


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


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


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

what about the .htaccess file?

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


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

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

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