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

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -