Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seemingly simple redirect in IIS using web.config file

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.

like image 700
robin Avatar asked Feb 21 '23 20:02

robin


1 Answers

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>
like image 71
Leniel Maccaferri Avatar answered Mar 06 '23 22:03

Leniel Maccaferri