Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to configure my web.config to redirect all the requests to http://sub.sub.domain.com to http://sub.domain.com. My project is hosted in a cloud service in Windows Azure.

Here is what I've tried (but not working).

<system.webServer>
   <rewrite>
      <rules>
         <rule name="Redirect sub.sub.domain.com to sub.domain.com">
            <match url="(.*)" />
            <conditions>
               <add input="{HTTP_HOST}"
                    pattern="^sub\.sub\.domain\.com$"
                    negate="true" />
            </conditions>
            <action type="Redirect"
                    url="http://sub.domain.com/{R:1}"
                    redirectType="Permanent" />
         </rule>
      </rules>      
   </rewrite>
</system.webServer>

Anyone can help?

Thank you very much!

share|improve this question

2 Answers 2

Ok, I finally went with the solution to handle this in the BeginRequest event in global.asax. Here's the code I used:

protected void Application_BeginRequest( object sender, EventArgs e )
{
  if( this.Request.Url.Host.StartsWith( "sub.sub.domain.com" ) )
  {
    var uriBuilder = new UriBuilder( this.Request.Url );
    uriBuilder.Host = this.Request.Url.Host.Replace( "sub.sub.domain.com", "sub.cuisinaviva.com" );

    this.Response.RedirectPermanent( uriBuilder.ToString() );
  }
}

And to add more information regarding my project, it is a Silverlight 5 application hosted in a ASP.NET MVC 4 project.

NOTE: I think that the solution Andy gave is probably good because I saw some similar awnsers elsewhere. I am just not sure that this is working with Azure...

share|improve this answer

Try updating your web.config to include the following:

<rule name="My redirection">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^sub.sub.domain.com$" />
    </conditions>
    <action type="Redirect" url="http://sub.domain.com/{R:1}" redirectType="Permanent" />
</rule>
share|improve this answer
    
Thanks Andy but it doesn't seem to work for me. I don't know if it's because of Azure or not but the redirect does not work. :( –  Jacques Bourque Oct 15 '13 at 22:39
    
Hi Jacques, is sub.sub.domain.com bound to your Azure deployment? –  Andy Oct 16 '13 at 11:13
    
If you mean that the domain is configured inside Azure then no. In my DNS server, I added a CNAME record for sub.sub.domain.com to point to mydomain.cloudapp.net. I also added a CNAME record for sub.domain.com to point to the same cloudapp.net address. –  Jacques Bourque Oct 16 '13 at 12:37
1  
To make sure that this works as expected I've just deployed a test solution to a new Azure Web Role and the suggested rule worked fine. –  Andy Oct 16 '13 at 20:06
    
I will have to do some more testing tomorrow then. Thank you for your input Andy. I'll keep you posted. –  Jacques Bourque Oct 17 '13 at 1:34

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.