web.config rewrite index.php for subdirectory

2019-07-07 15:49发布

问题:

On a server there are two webapps, a wordpress website, and a 'standalone' website in a subdirectory.

Both apps need a rewrite for index.php, and for wordpress this was done automatically, but now I also need a rewrite for the other app in the subdirectory.

To further clarify:

http://www.example.com/contact should redirect to http://www.example.com/index.php/contact http://www.example.com/subfolder/contact should redirect to http://www.example.com/subfolder/index.php/contact

It seems like a rather simple thing to do, but I can't seem to figure it out...

This is the web.config I have right now, how can I fix this?

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <defaultDocument>
            <files>
                <clear/>
                <add value="index.php"/>
                <add value="Default.htm"/>
                <add value="Default.asp"/>
                <add value="index.htm"/>
                <add value="index.html"/>
                <add value="iisstart.htm"/>
                <add value="default.aspx"/>
            </files>
        </defaultDocument>
        <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"/>
                </rule>
                <rule name="standalone" stopProcessing="true">
                    <match url="^" ignoreCase="false" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>