Skip to content

Instantly share code, notes, and snippets.

@jeremymoore
Last active February 10, 2020 18:00
Show Gist options
  • Save jeremymoore/82bebfbf164a07f63ea3ef4cdf5a1cd7 to your computer and use it in GitHub Desktop.
Save jeremymoore/82bebfbf164a07f63ea3ef4cdf5a1cd7 to your computer and use it in GitHub Desktop.
Web.Config for running Wordpress as a subdirectory on IIS. Additionally, created support for accessing the REST API, which changes routes to match the Site URL.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="static" patternSyntax="Wildcard">
<match url="*"/>
<conditions>
<add input="{REQUEST_URI}" matchType="Pattern" pattern="/wordpress/*" negate="true" />
<add input="{REQUEST_URI}" matchType="Pattern" pattern="/wp-json/*" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="index.html" redirectType="Found"/>
</rule>
</rules>
</rewrite>
</system.webServer>
<location path="wordpress">
<system.webServer>
<rewrite>
<rules>
<remove name="wordpress" />
<rule name="wordpress" patternSyntax="Wildcard">
<match url="*"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="wordpress/index.php" redirectType="Found"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</location>
<location path="wp-json">
<system.webServer>
<rewrite>
<rules>
<remove name="api" />
<rule name="api" patternSyntax="Wildcard">
<match url="*"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="wordpress/index.php" redirectType="Found"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</location>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment