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.

notice how ServerFault.com has no subdomain? If we want to do the same thing with our website -> redirect all traffic from www.***.com to ***.com, how can we do this?

At first, I thought it might be possible using IIS7's Url Rewrite free extension? And if so, can all requests be 301 redirected?

share|improve this question
    
Any reason why a CNAME wouldn't work? –  gravyface Nov 15 '10 at 1:57
    
CName's do not handle HTTP Status. it's just for resolving ip's. Totally seperate issue. More info: en.wikipedia.org/wiki/CNAME_record –  Pure.Krome Nov 30 '10 at 0:32

1 Answer 1

up vote 1 down vote accepted

Absolutally. Because IIS7 does not use .htaccess compatible rules though, it's not as simple as doing it in Apache or ISAP Rewrite.

This page here has all the details you need (due to IIS7's graphical nature, it's difficult to reproduce here). If you're into editing your web.config file manually, the correct procedure is:

<rule name="Canonical Host Name" stopProcessing="true">  
    <match url="(.*)" />  
    <conditions>  
        <add input="{HTTP_HOST}" negate="true" pattern="^example1.com$" />
        <add input="{HTTP_HOST}" negate="true" pattern="www.example1.com$" /> 
    </conditions>  
    <action type="Redirect" url="http://example.com/{R:1}" redirectType="Permanent" />  
</rule>
share|improve this answer
    
Awesome :) And i always use the config file (so I can easily migrate the site around) instead of using the UI. So, this looks like the Url Rewrite extension queries each incoming request. It then checks two regex patterns. First is for any subdomins? second is for the www subdomain. If found, does a 301 and stops. Yeah? –  Pure.Krome Nov 14 '10 at 23:37
    
@Pure - yes. If you're not interested in subdomains, then get rid of the first one and just use the 2nd input rule. (in fact that first rule overrides the 2nd rule anyway, as the 2nd rule is a subset of the first) –  Mark Henderson Nov 15 '10 at 0:00
    
two quick questions. 1) What's the configuration section this goes in? <?xml..?><configuration> ... <rewrite><rules><rule .../></rules></rewrite> .... </configuration> .. and 2) if this section is in the web.config ... and IIS ReWriter is not installed/added to the server .. this section is ignored BUT the site still runs (ie. this ignored section won't cause a site to crash .. because it's ignored). –  Pure.Krome Nov 30 '10 at 4:16
    
@Pure - unfortunately I'm not anywhere I can check the web.config file at the moment, but I'm fairly sure if you put it in your web.config file and rewrite isn't installed you get Error 500's on your site, so be careful! –  Mark Henderson Nov 30 '10 at 4:20

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.