First, when you add the web.config to a subdirectory, you are probably getting a 500 error because you are trying to add another rewrite rule of the same name. The “wordpress” rewrite rule from the root web.config is inherited by the web.config in the subdirectory, so when IIS sees that you want to define another rule named “wordpress”, it throws an error since it is already defined.
I would solve this problem by using a <location />
element to define a rule for the subdirectory. Your root web.config would look like this:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<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="index.php" redirectType="Found"/>
</rule>
</rules>
</rewrite>
</system.webServer>
<location path="wp1">
<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="wp1/index.php" redirectType="Found"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</location>
</configuration>
Note how you are first removing any rewrite rules named “wordpress” in the “wp1” location element, and then redefining the rule to point to the index.php in the subdirectory.
Another way you could do this, but I think is less desirable because you then have to maintain multiple web.configs, is to simply add the <remove />
element to the web.config you tried in the wp1 subdirectory. This would have the same effect. It may be the more ideal solution in your situation if you need to apply other settings via web.config in that subdirectory, but I would still recommend using the location element in the root web.config.
Disclaimer: I have not been able to test this myself, but I am fairly certain it should help solve your problem.
Edit: I forgot to mention that I added redirectType="Found"
to the action elements. The default redirect type is Temporary, which is inappropriate for these permalinks since they are not temporary. The Permanent redirect type is also inappropriate because it tells the browser/client to never use the original URL again, but we want them to continue to use the permalink. Thus, Found is the best type to be used for permalinks.
-
This reply was modified 8 years, 4 months ago by
Blair Allen.