Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to use an URL rewrite on an IIS 8.0 to rewrite existing URL's on a developer machine. The reason for this is that I don't want to change existing (old) code.

What I'm trying to achieve is to change the following code in the 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, I end up with:

<a href="foo.localhost">Foo Page</a>

And as you all know, this is not a very satisfying result.

So - how do I do this rewrite proper to achieve what I'm trying to do?

I know there are better ways of doing this, using application variables etc., but it's an old solution and I don't want to mess too much with the application itself. I want to keep the changes to a minimum. At least to begin with.

The rules I tried look like 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>

Would regex be the preferable solution to this problem?

share|improve this question
    
So... What did you try that resulted in foo.localhost? :) –  Mathias R. Jessen May 18 '13 at 23:09
1  
That's a valid question. My mistake for not describing that in the first place. Q is edited. :-) –  CB Du Rietz May 18 '13 at 23:47
add comment

1 Answer 1

up vote 1 down vote accepted

I had this question answered in another forum. This is a recap of that answer, for the record.

The correct rewrite looks like 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="{R:1}foo.localhost{R:2}" />
      </rule>
    </outboundRules>
  </rewrite>
</system.webServer>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.