We help IT Professionals succeed at work.

301 redirect

I would like to setup a 301 redirect so that my home page index.aspx always defaults to the domain URL.  So for example, I would like for www.mysite.com/index.aspx to redirect automatically to www.mysite.com.

Can someone please help me with this?
Comment
Watch Question

CERTIFIED EXPERT

Commented:

Author

Commented:
When I tried this, it seems to go into an endless loop without displaying the page.  Is there another way?
CERTIFIED EXPERT

Commented:
In your index.aspx, try this.

<%@ Page Language="C#" %>
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
	Response.Status = "301 Moved Permanently";
	Response.AddHeader("Location","/");
}
</script>

Open in new window

Consultant
CERTIFIED EXPERT
Commented:
in codebehind its may be never ending loop . Where as using javascript u may achieve . For eg.
In javascript . Get url using document.url and check it consists of index.aspx if it has navigate with some special query string and then check in code behind if that special  query string is not null then do that with 301 redirect . Sorry , Am not having visual studio ide right now using mobile version.  Hope you get into a right direction with this .

Explore More ContentExplore courses, solutions, and other research materials related to this topic.