Fırat Tuncer
Fırat Tuncer

Reputation: 85

Url Redirection

There are 2 website domain names; one is www.website.com.tr, and the other is website.com.tr .

All I want to do is, if the user writes to the browser's address bar website.com.tr, I want the 3w version to be opened.

Is it possible to do this by writing some server-side code like:

if (givenURL=="website.com.tr")
{
   url.Redirect("www.website.com.tr");
} 

... or am I better off to pasting below code block to the global.asax file?

private void context_BeginRequest(object sender, EventArgs e)
{
    HttpApplication application = (HttpApplication) sender;

    if (!application.Request.Url.ToString().Contains("http://www."))
    {
        application.Response.Redirect(
            application.Request.Url.ToString().Replace("http://", "http://www."));
    }
}

Regards.

Upvotes: 0

Views: 98

Answers (3)

BonyT
BonyT

Reputation: 10940

The simplest solution is to the create a CNAME record on the DNS server to map both URLs to the same application.

http://en.wikipedia.org/wiki/CNAME_record

Upvotes: 3

Darin Dimitrov
Darin Dimitrov

Reputation: 1039498

It would be better to handle this at the web server or even at DNS.

Upvotes: 1

Eric Andres
Eric Andres

Reputation: 3417

If it's your domain name to work with, why not just set up DNS to redirect website.com.tr to www.website.com.tr? My hosting company did it by default for me.

Upvotes: 0

Related Questions