mamu
mamu

Reputation: 12414

Redirect site from www.a.com to a.com in asp.net mvc

We have asp.net mvc 2 site which allows www and without any subdomain. For consistency we want to redirect any www request to without any subdomain.

Just like stackoverflow does.

Where and how it should be done? using asp.net Requestrouting?

Also i want it for all request to the site not just for home

Upvotes: 0

Views: 190

Answers (3)

dmulvi
dmulvi

Reputation: 639

I use URL Rewrite for this. You can download/install here: IIS Url Rewrite

After installing that to to IIS, select the website you want to create the rule for and then click the URL Rewrite module icon.

Click the "Add Rule" link in the top right corner. Select "Canonical Domain Name" from the premade rules in the dialog box that pops up. From there select the non-www option.

This tool adds a rule to your web.config file. URL Rewrite must be installed on the webserver you deploy your app to in order for the rules to work.

This is just the tip of the iceberg of what the tool can do. I find myself using it all the time. Here is a brief tutorial about using it: learn.iis.net/page.aspx/460/using-the-url-rewrite-module/

(just add http:// before that link above) (I'm new so I only get one hyperlink...aboo)

Upvotes: 1

mattk
mattk

Reputation: 1365

It would be simplest to configure the redirect in IIS. It can preserve the path and querystring when redirecting to the new domain.

http://forums.iis.net/t/1157428.aspx

Upvotes: 2

Neel Basu
Neel Basu

Reputation: 12904

I don't know ASP However in a ASP Page you can add Location Header to redirect. I am not sure about the exact function name in asp. However it might be something like

<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://site.com/"
%>

and put this file on www as index.aspx

Upvotes: 0

Related Questions