jammy-d0dger
asked on
Using RewriteMap in web.config for 301 redirects
Hi experts,
Tearing my hair out here.
I want to use the web.config file to handle some 301 redirects. I have a RewriteMap and this is firing successfully but only if I don't include the domain name in the key value. the problem is, I want to be able to have entries in the rewriteMap that have full domain and paths so that I can differentiate entries for different domains.
e.g.
<rewriteMaps>
<rewriteMap name="Redirects">
<add key="mydomain1.com/book-ev ent/" value="myNEWdomain.com/eve nts1/" />
<add key="mydomain2.com/book-ev ent/" value="myNEWdomain.com/eve nts2/" />
</rewriteMap>
</rewriteMaps>
But as soon as I add the domain, the rule doesn't seem to fire/match and I just get a 404.
e.g. this works:
<rewriteMaps>
<rewriteMap name="Redirects">
<add key="/book-event/" value="/events1/" />
</rewriteMap>
</rewriteMaps>
...but is of no use because I can't differentiate between domain names.
This is my code in full, from the web.config:
<rewrite>
<rewriteMaps>
<rewriteMap name="Redirects">
<add key="mydomain1.com/book-ev ent/" value="myNEWdomain.com/eve nts1/" />
<add key="mydomain2.com/book-ev ent/" value="myNEWdomain.com/eve nts2/" />
</rewriteMap>
</rewriteMaps>
<rules>
<rule name="Redirect rule1 for Redirects">
<match url=".*" />
<conditions>
<add input="{Redirects:{REQUEST _URI}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
Any help, much appreciated. Maybe I just have my regular expression all wrong?
Tearing my hair out here.
I want to use the web.config file to handle some 301 redirects. I have a RewriteMap and this is firing successfully but only if I don't include the domain name in the key value. the problem is, I want to be able to have entries in the rewriteMap that have full domain and paths so that I can differentiate entries for different domains.
e.g.
<rewriteMaps>
<rewriteMap name="Redirects">
<add key="mydomain1.com/book-ev
<add key="mydomain2.com/book-ev
</rewriteMap>
</rewriteMaps>
But as soon as I add the domain, the rule doesn't seem to fire/match and I just get a 404.
e.g. this works:
<rewriteMaps>
<rewriteMap name="Redirects">
<add key="/book-event/" value="/events1/" />
</rewriteMap>
</rewriteMaps>
...but is of no use because I can't differentiate between domain names.
This is my code in full, from the web.config:
<rewrite>
<rewriteMaps>
<rewriteMap name="Redirects">
<add key="mydomain1.com/book-ev
<add key="mydomain2.com/book-ev
</rewriteMap>
</rewriteMaps>
<rules>
<rule name="Redirect rule1 for Redirects">
<match url=".*" />
<conditions>
<add input="{Redirects:{REQUEST
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
Any help, much appreciated. Maybe I just have my regular expression all wrong?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
The following is the example of redirection from http to https and its working fine for me. Try with following code by changing the urls required by you and it should work fine for you.
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
The following is the example of redirection from http to https and its working fine for me. Try with following code by changing the urls required by you and it should work fine for you.
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
ASKER
Sorry, not sure I follow. How does this become relevant to my question about making redirects work for both http://www.mydomain1.com AND http://mydomain1.com
ASKER
No comments directly related to my question were offered. Worked it out myself and posted code.
See the solution provided in this post
http://forums.iis.net/t/1155754.aspx