I have a Wordpress website installed in IIS and it is working fine. On a subfolder I have and ASP.NET application which also works allright.
Wordpress URL rewriting causes a series of problems on the application living in the subfolder. The solution for that is simple: my root web.config file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
<location path="." inheritInChildApplications="false">
<system.webServer>
<rewrite>
<rules>
<rule name="wordpress" enabled="true" patternSyntax="Wildcard">
<match url="*" negate="false"/>
<conditions logicalGrouping="MatchAll">
<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>
</rewrite>
</system.webServer>
</location>
</configuration>
The key thing is here: inheritInChildApplications="false"
inside the <location>
tag. This will prevent the rewrite rules from being propagated to the child ASP.NET application, which causes harm, as I have explained before.
So far, so good.
But imagine that I simply enter the Permalinks configuration page which lives in this path: wp-admin/options-permalink.php
.
In that case, something terrible happens: Wordpress automatically reads my web-config file, probably searching for tag <system.webServer>
under the <configuration>
tag. But it is not there because I have wrapped <system.webServer>
under the <location>
tag.
Since it doesn't find the rewrite rules there, Wordpress simply adds the <system.webServer>
block all over again, causing it to duplicate and it saves the web.config file.
Having two <system.webServer>
blocks on the web.config file causes the website to break miserably with a 500 error message. The server log will tell me that Config section 'system.webServer/rewrite/rules' already defined. Sections must only appear once per config file
.
Please, not that I don't have to hit 'save changes' on the Permalinks config page for this tragedy to happen, all I have to do is enter the page. Wordpress will then do all the checks and resave the web.config file on its own.
Although I don't plan to enter that configuration page, I consider it a risk that entering that page by accident one year from now when the website is in production will trigger these horrid 500 errors.
So after all this long post, my question is: do you know of any methods or any configurations that will stop Wordpress from automatically saving the web.config file again when I enter the Permalinks configuration page? Thank you.
flush_rewrite_rules_hard
filter may be your answer.apply_filters ('flush_rewrite_rules_hard', false);
both in wp-config.php and my theme's functions.php with no success. Thank you.add_filter
, so your filter is applied to the value when core usesapply_filters
to run your filter.