PHP on IIS7 - Receiving "Object Moved" html page instead of actually redirecting

I figured it out. The Location header must be an absolute path to auto-redirect. If it's a relative path it doesn't redirect.


I had a similar issue but the path was already absolute. I solved it by specifically sending a 301 header before the location. PHP is supposed to detect redirects and do this automatically but wasn't doing.

header("HTTP/1.1 301 Moved Permanently");
header("location:http://www.mysite.com/mypage.php");

I had this problem using PHP on IIS7 using absolute URL. Bugged me for a little while. Ensure that you put exit(); after your header('Location: https://domain.tld/resource'); the header doesn't stop execution, and the function will otherwise return somewhere giving maybe unexpected results.

Tags:

Php

Iis

Iis 7.5