Removing trailing slashes in WordPress blog hosted on IIS

Posted by Zishan on Server Fault See other posts from Server Fault or by Zishan
Published on 2012-03-28T12:54:40Z Indexed on 2012/04/05 23:32 UTC
Read the original article Hit count: 254

Filed under:
|
|

I have a WordPress blog hosted in my IIS virtual directory that has all URLs ending with a forward slash. For example:

http://www.example.com/blog/

I have the following rules defined in my web.config:

<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="Redirect-domain-to-www" patternSyntax="Wildcard" stopProcessing="true">
    <match url="*" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="example.com" />
    </conditions>
    <action type="Redirect" url="http://www.example.com/blog/{R:0}" />
</rule>

In addition, I tried adding the following rule for removing trailing slashes:

<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>

It seems that the last rule doesn't work at all. Anyone around here who has attempted to remove trailing slashes from WordPress blogs hosted on IIS?

© Server Fault or respective owner

Related posts about iis

Related posts about iis7