Question

I want to have a redirect from www.subdomain.domain.com to subdomain.domain.com in web.config

i'm using Urlrewrite in my web.config.

this is my rule, what is wrong with this? it does not work ..

  <rule name="Redirecton" patternSyntax="ECMAScript" stopProcessing="true">
      <match url=".*" />
      <conditions>
          <add input="{HTTP_HOST}" pattern="^www.*.domain.com*" />
      </conditions>
      <action type="Redirect" url="http://{C:1}.domain.com/{C:2}" />
  </rule>

anyone can help me about this issue ?

EDIT : it shows this error in page :

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator to inform of the time the error occurred and of anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Was it helpful?

Solution

The following should work - at least it did in a short test for me:

<rule name="Redirecton" patternSyntax="ECMAScript" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^www\.(.*)\.test\.at(.*)" />
    </conditions>
    <action type="Redirect" url="http://{C:1}.test.at/{R:0}" />
</rule>

What I changed:

  • Escaped the . as \.
  • Created captures using parantheses
  • Adapted the redirect target to work - I am not shure why it is that way:
    • {C:0} is the complete input string
    • {C:1} is the first capture
    • {C:2} is empty
    • {R:0} is the second capture
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top