Forces IIS Slash Even With Rewrite URL To Remove It

I cannot remove the end braids of my site URLs even with URL rewriting: http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/ .

Disappointment is indeed, as it should be so simple, but my attempts have yielded no results.

I even went so far as to create a test directory and an added file called desktops.aspx and a subfolder called desktops.

without the subdirectory "/ test / desktops" it loads fine, since I set the default document for viewing .aspx desktops.

with a subfolder created and still referencing "/ test / desktop", it forces a slash and looks into a subdirectory.

Why is IIS doing this since it is assumed that it first searches for the file and then the subdirectory correctly? Are there any server-side settings that will force backslash?

Rewrite url:

<rule name="SEO - Remove trailing slash" stopProcessing="false">
<match url="(.+)/$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_METHOD}" pattern="GET" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="_{R:1}" />
</rule>

any help would be appreciated

+5
source share
3 answers

You use a type action Rewrite, but you want to Redirect.

Change the configuration to:

<rule name="SEO - Remove trailing slash" stopProcessing="false">
  <match url="(.*)/$" />
  <conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
  </conditions>
  <action type="Redirect" url="{R:1}" />
</rule>

You also need to change url="(.+)/$"to url="(.*)/$".

Tip:

The best way to test your pattern is to use the IIS test pattern tool.
At the root of your site -> URL Rewrite -> Create an empty rule -> click a test pattern:

+4
source

, , - PDF, , , Windows Server 2008 R2 IIS 6.1:

-, , Features URL Rewrite, Actions ( ) Add Rule(s) Append or Remove the trailing slash symbol. remove if exists.

, .

0

, .

, - MVC, , - asp.net.

, . www.example.com/test www.example.com/test/ .

, , , URL- , .

www.example.com/test/, www.example.com/test. ! . IIS www.example.com/test/, . Boo.

https://support.microsoft.com/en-us/kb/298408, IIS 6, , , .

, - asp.net, /test , IIS -, - . , , .

However! My requirement was for MVC and configured routes that are not directories. So I tried this again on the MVC website and the redirect to remove the trailing slash worked fine.

The rule in which I ended up:

<rule name="RemoveDatSlash" 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>

Hope this helps!

0
source

All Articles