Forum Moderators: open

Message Too Old, No Replies

Permanent 301 in Global.asax

         

olly79

2:19 pm on Oct 3, 2009 (gmt 0)

10+ Year Member



Hi all,

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

Ocean10000

5:58 pm on Oct 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



IIS has a default redirect mapping index.aspx to /. And your redirect is telling it to do another redirect back to /. This is in effect causing a redirect loop which will never end.

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]

olly79

8:43 pm on Oct 3, 2009 (gmt 0)

10+ Year Member



Hi,

I could move to a virtual private server and then we could apply some config to the IIS - therefore what would your recommendation be to resolve this through IIS? Thanks

Ocean10000

2:08 am on Oct 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you are thinking of moving to a virtual private server you might want too look into few options.

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.

marcel

3:26 pm on Oct 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you move to a virtual server I would recommend Windows Server 2008 (with IIS 7)

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>