Forum Moderators: open
Just wondering if anyone can help me with the following issue.
I want to create a permanent 301 redirect for the sites extension /index.aspx page back to root; however, the site is on a hosted account; therefore Config changes to IIS are out of the question.
The code I have in my Global.asax file is as follows:
if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("index.aspx"))
{
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.StatusCode = 301;
HttpContext.Current.Response.AddHeader("Location", VirtualPathUtility.ToAbsolute("~"));//Would move to root web
}
However, I still get the following error message when I upload the Global file to the web server:
The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
I would really appreciate someones help as I'm really struggling with this and really need to have this up and running.
Many thanks
I do not know currently of a simple way around this without other tools which you do not have access too.
Reference
/default.aspx and "/" .why is it indexing duplicate pages [webmasterworld.com]
I have not played with IIS 7 much at all yet to know if this same problem applies to it or not.
I know others have recommended ISAPI_Rewrite [isapirewrite.com] before, and reading they have a free lite addition. I have never used it personally so I can not say much about it one way or another.
Install the IIS 7 rewrite module [iis.net] and add the following to your web.config file:
<rule name="Default Document" stopProcessing="true">
<match url="(.*)index.aspx"/>
<action type="Redirect" url="{R:1}" redirectType="Permanent"/>
</rule>