POST
Symfony on IIS
For those of you who must create a Symfony website on Windows/IIS, here’s a sample web.config that works.
It’s been tested with Symfony 3 and 4. It’s explained in detail below.
Details
defaultDocument
The defaultDocument
section tells IIS to serve the index.php script when the document root is visited, instead of its defaults.
<defaultDocument>
<files>
<remove value="iisstart.htm" />
<remove value="Default.htm" />
<remove value="Default.asp" />
<add value="index.php" />
</files>
</defaultDocument>
Rewrite rules
@todo
<rule name="Symfony: Redirect index.php/anything to /anything" stopProcessing="true">
<match url="^index\.php(/(.*)|$)" ignoreCase="false" />
<action type="Redirect" url="/{R:2}" redirectType="Permanent" />
</rule>
<rule name="Symfony: Existing files" stopProcessing="true">
<match url=".?" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
</conditions>
<action type="None" />
</rule>
<rule name="Symfony: All the rest to index.php" stopProcessing="true">
<match url=".?" ignoreCase="false" />
<action type="Rewrite" url="/index.php" />
</rule>