简体   繁体   中英

IIS URL Rewrite: Add trailing slash in url only once

I have a rule in IIS to append a slash at the end (if there is no). It is working fine but in my case, I only need it for the first time. I have a reverse proxy on IIS to forward the request to another server. With this rule, it appends the slash all the time.

How I can modify the rule to append the slash only if there is not any after a keyword like 'myapp' so that it appends the slash if a URL is like http://myserver/myapp

 <rule name="AddTrailingSlashRule1" stopProcessing="true">
                <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>

I tried changing the regular expression in url="(.*myapp[^/])$" but it does not work.

As far as I know the [^/] means there is a character which is not the '/'. So your regex will not work well for the myapp.

The right regex is .*myapp$ .

Result:

在此处输入图片说明

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