Seemingly simple redirect in IIS using web.config

2019-02-24 08:14发布

问题:

I've restructured a WordPress site that's hosted on a Windows server, so I'm trying to redirect with a web.config file. I've tried dozens of variations from examples and I can't make it work. The new urls have changed from this:

www.mysite.com/wp/whatever-else

to this:

www.mysite.com/whatever-else

Some examples I've tried include:

<rewrite>
<rules>
    <rule name="WP Redirect">
        <match url="^(.*)/wp/(.*)" />
        <action type="Rewrite" url="{R:1}/{R:2}" />
    </rule>
</rules>
</rewrite>

<rewrite>
<rules>
    <rule name="WP Redirect">
    <match url="^(.*)/?wp(.*)" />
    <action type="Rewrite" url="http://www.mysite.com/{R:1}" />
    </rule>
</rules>
</rewrite>

<rewrite>
<rules>
    <rule name=""WP Redirect" stopProcessing="true">
    <match url="^com/wp/?" />
    <conditions logicalGrouping="MatchAny" trackAllCaptures="true">
    </conditions>
    <action type="Redirect" url="{R:1}/" />
    </rule>
</rules>
</rewrite> 

Any suggestions? I'm stumped. Thanks.

回答1:

Try this one:

<rewrite>
  <rules>
    <rule name="WP Redirect" stopProcessing="true">
      <match url="^wp/(.*)$" ignoreCase="false" />
      <action type="Redirect" redirectType="Permanent" url="http://www.mysite.com/{R:1}" />
    </rule>
  </rules>
</rewrite>