Skip to content
Advertisement

How to know why a 301 redirect occurred in a PHP application in IIS?

IIS logging has logged that a specific GET request as been redirected.

Here is the relevant entry (ip address removed):

2021-10-06 02:48:59 xx.xx.xx.xx GET /test - 80 - xx.xxx.x.xxx Mozilla/5.0+(Windows+NT+6.1;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/93.0.4577.82+Safari/537.36 - 301 0 0 1

The application /test consists of a single index.php file that echo‘s the word ‘hello’.

There are no url redirect rules set up in IIS. Nor are there any calls to header()

Any ideas as to how to determine why a redirect would occur on a simple web application like this? Or tips on how one can find out the cause?

For context, the server which this simple application runs on sits behind an AWS load balancer. However, the redirect definitely is occuring on the IIS server and not in some firewall or network configuration.

Additionally, the redirect only occurs when there is no “/” on the end. If there is a “/” on the end, it works. (status code = 200). I have more detailed info in this question here

Advertisement

Answer

This is IIS built-in behavior. When a URL maps to a directory and the trailing slash is missing, IIS sends a redirect to add the slash. It is known as a “courtesy redirect”, as explained here.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement