views:

29

answers:

3

I'm currently planning to deploy a site with a third party hosting provider. I will only have access to the server via ftp and a tool similar to cpanel called WebsitePanel.

No access to IIS set up or configs.

Is there anyway to redirect http://www.example.com to http://example.com?

A: 

Typically, the "tool similar to cpanel" should give you this option.

Failing that, you should be able to:

a) set a custom 404 page pointing, to, say, myredirector.asp [or whatever server-side script you wish to use]
b) in myredirector.asp [or whatever] , do a server-side redirect as appropriate.

Not as clean as a straight IIS redirect, but it works pretty good.

Wyatt Barnett
+2  A: 

Place this in your web.config using your values for domain.com. This leverages the URL rewrite rules of the web.config and IIS 7.

 <system.webServer> / <rewrite> / <rules>

    <rule name="Remove WWW prefix" >
    <match url="(.*)" ignoreCase="true" />
    <conditions>
    <add input="{HTTP_HOST}" pattern="^www\.domain\.com" />
    </conditions>
    <action type="Redirect" url="http://domain.com/{R:1}"
        redirectType="Permanent" />
    </rule>
Tommy
thanks, though I'd rather change this at the DNS level I can't, so this solution does exactly what I need and works perfectly. much appreciated.
Chris
A: 

I'd suggest you do this through the domain's DNS configuration, rather than through your application. It's much simpler and doesn't rely on application code to work (so if you deploy a whole new application, you don't have to remember to add any config entries or similar).

Dan Puzey