iis - Using URL Rewrite to change part of URL -
i'm trying use url rewrite on iis 8.0 rewrite existing url:s on developer machine. reason don't want change existing (old) code.
what i'm trying achieve change following code in response stream:
<a href="http://www.foo.com/path/page.asp?a=1">foo page</a>
into:
<a href="http://www.foo.localhost/path/page.asp?a=1">foo page</a>
but when i'm trying, end with:
<a href="foo.localhost">foo page</a>
and know, not satisfying result.
so - how do rewrite proper achieve i'm trying do?
i know there better ways of doing this, using application variables etc., it's old solution , don't want mess application itself. want keep changes minimum. @ least begin with.
the rules tried this:
<system.webserver> <rewrite> <outboundrules> <rule name="foo.com" enabled="true"> <match filterbytags="a, area, base, form, frame, head, iframe, img, input, link, script" pattern="foo.com" /> <action type="rewrite" value="foo.localhost" /> </rule> </outboundrules> </rewrite> </system.webserver>
i guess there regex magic should using.
your rule needs changed to:
<rule name="foo.com" enabled="true"> <match filterbytags="a, area, base, form, frame, head, iframe, img, input, link, script" pattern="^(.*)foo.com(.*)$" /> <action type="rewrite" value="{r:1}foo.localhost{r:2}" /> </rule>
in pattern, ^(.*)
match (0 or more characters) beginning before foo.com
, (.*)$
after foo.com
until end.
you can use references in action
, {r:1}
take value matching (.*)
before foo.com
, {r:2}
value matching (.*)
after foo.com
Comments
Post a Comment