Install Config Wiki

All about installing, configuring and troubleshooting

User Tools

Site Tools


suggested_web_config_file_wordpress_iis_server

Suggested web.config for WordPress on IIS

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <defaultDocument>
            <files>
                <clear />
                <add value="index.php" />
            </files>
        </defaultDocument>
        <rewrite>
            <rules>
                <clear />
                <rule name="WordPress Rule" stopProcessing="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" />
                </rule>
            </rules>
            <outboundRules>
                <clear />
            </outboundRules>
        </rewrite>
    </system.webServer>
</configuration>

Credit to Todd Miller of Dayton Ohio. Screen name “Toddses” See Git Hub Gist: https://gist.github.com/Toddses/7f3729ddf7c6466bb3dc

Todd's Comments: Note the line <action type=“Rewrite” url=“index.php” /> is key. The rule I found through official WP channels suggests using url=“index.php?page_id={R:0}” but this was flawed. Any post that began with a number would return a 404 error.

Now, my commmentary (not Todd's): Following is the same code as above in the web.config file EXCEPT as may be modified by IIS in the event that you have configured IIS for a new Handler Mapping for a specific website in order to introduce an upgraded FastCgi module executable, let's say, upgrading from PHP7 to PHP 8. Let's assume that your IIS web server is presently configured by DEFAULT for the PHP7.4 FastCGI executable, but you manually configure a specific website in IIS Management by added FastCGI Module for PHP8 executable. This PHP8 configuration is auto inserted by IIS into the Web.Config file in order to override the default PHP7 FastCGI setting. See for example, the <handlers> </handlers> element inserted below:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <defaultDocument>
            <files>
                <clear />
                <add value="index.php" />
            </files>
        </defaultDocument>
        <rewrite>
            <rules>
                <clear />
                <rule name="WordPress Rule" stopProcessing="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" />
                </rule>
            </rules>
            <outboundRules>
                <clear />
            </outboundRules>
        </rewrite>
            <handlers>
                 <add name="PHP8_1" path="*.php" verb="*" modules="FastCgiModule" scriptProcessor="C:\php_8_1\php-cgi.exe" resourceType="File" />
            </handlers>
    </system.webServer>
</configuration>
suggested_web_config_file_wordpress_iis_server.txt · Last modified: 2023/10/02 15:52 by wikiadmin