Reputation: 85
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
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
Reputation: 1039498
It would be better to handle this at the web server or even at DNS.
Upvotes: 1
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