Rewrite rules not matching anything below 1 sublevel

77 Views Asked by At

I'm trying to write a redirect rule for an asp site in the web.config and I'm running into an issue with subfolders.

If I visit http://www.thesite.com/folder it redirects to http://www.thesite.com just fine, but if I visit a subfolder like http://www.thesite.com/folder/folder it doesn't - could anyone help me with my match rule so it sends ALL traffic to the root?

The rule below is what I have just now:

<?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                     <rule name="Remove trailing slash" stopProcessing="true">
                          <match url="(.*)/$" />
                               <conditions>
                                   <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                                   <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                               </conditions>
                               <action type="Redirect" redirectType="Permanent" url="{R:1}" />
                        </rule>
                        <rule name="redirect all requests" stopProcessing="true">
                            <match url=".+" ignoreCase="false" />
                                 <conditions logicalGrouping="MatchAll">
                                      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
                                 </conditions>
                                 <action type="Rewrite" url="/index.php" appendQueryString="false" redirectType="Permanent" />
                     </rule>
                 </rules>
    </rewrite>
</system.webServer>

1

There are 1 best solutions below

0
On

Does anyone answer any more, or just browse for post tags to edit? I found the solution myself - for those who may be interested in an actual solution, I changed the operator to the following:

<match url="(.*)/$" />

This solved the issue