简体   繁体   中英

Issue redirecting with IIS url rewriting

I have an Asp.Net website which also has a WordPress blog in the subdirectory. I've having trouble with one of the redirect rules I'm trying to create.

I have this rule in web.config:

    <rule name="Remove trailing slash">
      <match url="^(.*(?!/blog/).*)$" />
      <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>

What it attempts to do is, remove the trailing slash from every page that doesn't have the blog directory within the url.

It works for most parts.

Any pages on the website work:

http://www.mysite/terms

The blog home page works:

http://www.mysite/blog

What doesn't work is:

http://www.mysite/blog/my-latest-post

For some reason the page is not redirecting properly (or going round in circles).

Any ideas as to how this can be corrected?

I would try something like

<rule name="Remove trailing slash">
  <match url="^(.*)/$" />
  <conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    <add input="{HTTP_HOST}" pattern"^.*/blog/.*$" negate="true" />
  </conditions>
  <action type="Redirect" redirectType="Permanent" url="{R:1}" />
</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