asp.net - Redirect from http://sitename.com to http://www.sitename.com -
i using asp.net 4. want 301 redirect http://sitename.com http://www.sitename.com.
what's best way (and optional ways) it?
my site getting indexed on ip address. how can stop that.
you simple check in page_load
:
protected void page_load(object sender, eventargs e) { string servername = httputility.urlencode(request.servervariables["server_name"]); string filepath = request.filepath; if (!servername.tolower().startswith("www.")) servername = "www." + servername; response.redirect("http://" + servername + filepath); }
or add following htaccess file:
options +followsymlinks rewriteengine on rewritecond %{http_host} ^domain.com [nc] rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
replacing domain.com
, http://www.domain.com
domain.
Comments
Post a Comment