开发者

ASP .NET 301 redirect create problem for some users

This is the code I use to redirect from www. to non www. version of my site

void Application_BeginRequest(object sender, EventArgs e)
{
    string authority = Request.Url.Authority;
    if (authority.StartsWith("www."))
    {
        authority = authority.Remove(0, 4);
        string newUrl = "http://" + authority + Request.Url.PathAndQuery;

        Response.Clear();
        Response.Status = "301 Moved Permanently";
        Response.AddHeader("Location", newUrl);
        Response.End();            
    }
}

this is the tool I used to validate if the code above work as expected:

htt开发者_StackOverflow中文版p://www.internetofficer.com/seo-tool/redirect-check/

While everything works as expected for almost all users, some of them has complained they can't access the site. I logged in to their computer using TeamViewer and indeed, there was a problem. When they try to acces the site, FF and IE gives an error: it looks like the site you wanted isn't there.

What should be the problem ?


You're using .PathAndQuery, so take a look into this answer: Hyperlinks stop working in firefox after redirect?

problem solved by removing question-mark from redirect url.

So, try to use Request.Url.LocalPath property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜