Mostly User dont type "www" before our domain name, either they are searching in google or directly into address bar of browser.
for example, user type "indianic.com" in address bar of browser.
then the url of our website looks like this "http://indianic.com", this really looks odd.
what if our URL automatically redirect to http://www.indianic.com, Yes now its look nice and seo friendly.
This is possible, by adding just below code in your page load event in c#.
For other languages developer, need not need to worry, this is simple "if condition", you can easlily covert it into your language.
Please find below sample code.
protected void Page_Load(object sender, EventArgs e)
{
if (Request.ServerVariables["SERVER_NAME"] != "localhost")
{
if (sCheckUrl.IndexOf("http://") == 0)
{
if (sCheckUrl.IndexOf("http://www.") != 0)
{
Response.Redirect(sCheckUrl.Replace("http://indianic", "http://www.indianic"));
}
}
else if (sCheckUrl.IndexOf("https://") == 0)
{
if (sCheckUrl.IndexOf("https://www.") != 0)
{
Response.Redirect(sCheckUrl.Replace("http://indianic", "http://www.indianic"));
}
}
}
}
Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Asp.Net Developer
Indianic Infotech Ltd (India)
rajesh@indianic.com
No comments :
Post a Comment