简体   繁体   中英

Rewriting URL causing opening folder with same name

I have the following rule to remove .aspx from the end of url:

<rewrite>
    <rules>
        <clear />
        <rule name="Redirect to clean URL" enabled="true" stopProcessing="true">
            <match url="^([a-z0-9/]+).aspx$" ignoreCase="true" />
            <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
            <action type="Redirect" url="{R:1}" />
        </rule>
        <rule name="RewriteASPX" enabled="true">
            <match url="(.*)" />
            <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            </conditions>
            <action type="Rewrite" url="{R:1}.aspx" />
        </rule>
    </rules>
</rewrite>

Now the problem is that a few specific pages with the same name of folder available in that path, gets opened every time instead of that site.

This is my site

在此处输入图片说明

Suppose when i click a link City.aspx , it opens the folder(in FTP) with the name City instead of opening that page.

[Edited]

Removing <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> solved the problem but now entering the sitename in the url is not working.

Solved the problem by removing this:

<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />

and adding this:

<rule name="Canonical" stopProcessing="true">
   <match url=".*"/>
      <conditions>
         <add input="{HTTP_HOST}" pattern="^([a-z]+[.]com)$"/>
      </conditions>
         <action type="Rewrite" url="http://www.{C:0}/{R:0}/Index.aspx" redirectType="Permanent"/>
</rule> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM