Share via


Redirects in IIS using wildcards

Question

Tuesday, July 25, 2017 3:06 PM

Hi can someone provide a solution to redirect the following:

Anything that comes from http://OldSite/sites/subdirectories...

to

http://NewSite/New/subdirectories...

I have tried using the various wild cards $S, $Q, $P, $V but noting copied the subdirectories...

Thank you!

All replies (2)

Wednesday, July 26, 2017 2:22 AM âś…Answered | 1 vote

Hi AJCH,

It is recommended to use regex instead of wildcard to achieve such kind of redirect, please enable install the URL rewrite module in IIS:

https://www.iis.net/downloads/microsoft/url-rewrite

Then add this rule to web.config <rewrite>/<rules>section

  <rule name="rewrite1" enabled="true" stopProcessing="true">

                    <match url="(.*)" />

                    <conditions trackAllCaptures="true">

                        <add input="{URL}" pattern="^/sites/(.*)$" />

                        <add input="{HTTP_HOST}" pattern="OldSite" />

                    </conditions>

                    <action type="Redirect" url="http://NewSite/New/{C:1}" appendQueryString="true" redirectType="Permanent" />

                </rule>

Best Regards,

Candy

Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected].


Wednesday, July 26, 2017 8:48 PM

Thank you Candy for your reply. It works for me! Very much appreciated. Cheers!