404页显示请求的页面 [英] 404 page that displays requested page

查看:89
本文介绍了404页显示请求的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近迁移一个网站,以新的CMS(一把umbraco)。很多环节都变了,但他们可以通过搜索URL中的节拍作容易纠正,所以我想写点东西,将重定向到正确的页面,如果找不到旧的。那部分是没有问题的。

I recently migrated a website to a new CMS (Umbraco). A lot of the links have changed, but they can be easily corrected by searching for patters in the url, so I would like to write something that will redirect to the correct page if the old one is not found. That part isn't a problem.

我怎样才能获得请求的URL,浏览器将被重定向到我的自定义404页之后。我试着使用:

How can I obtain the requested URL after the browser is redirected to my custom 404 page. I tried using:

request.ServerVariables("HTTP_REFERER") 'sorry i corrected the typo from system to server.

但是,这并不能正常工作。

But that didn't work.

任何想法?

该网站是在IIS 6.0上。
我们也可以考虑使用301重定向,但我们没有知道什么网页人们书签,有几百页的任何方式,所以没有一个是热衷于消费创造了301的时间。

The site is on IIS 6.0. We did consider using 301 redirects, but we don't have any way of knowing what pages people have bookmarked and there are a few hundred pages, so no one is keen on spending the time to create the 301's.

推荐答案

我基本上你在自定义404错误处理页面问同样的事情。在IIS 6原始URL是在查询字符串。在code以下显示了如何抓住原始URL,然后转发给用户。以我为例,我从旧的ASP切换到新的ASP.NET,所以所有的.asp页必须被转发到.aspx页。此外,某些URL改变,因此我期待在旧的URL关键字和转发。

I do basically the same thing you ask in a custom 404 error handling page. On IIS 6 the original URL is in the query string. The code below shows how to grab the original URL and then forward the user. In my case I switched from old ASP to new ASP.NET, so all the .asp pages had to be forwarded to .aspx pages. Also, some URLs changed so I look for keywords in the old URL and forward.

//did the error go to a .ASP page?  If so, append x (for .aspx) and 
//issue a 301 permanently moved
//when we get an error, the querystring will be "404;<complete original URL>"
string targetPage = Request.RawUrl.Substring(Request.FilePath.Length);

if((null == targetPage) || (targetPage.Length == 0))
    targetPage = "[home page]";
else
{
     //find the original URL
    if(targetPage[0] == '?')
    {
    	if(-1 != targetPage.IndexOf("?aspxerrorpath="))
    	     targetPage = targetPage.Substring(15); // ?aspxerrorpath=
    	else
    	     targetPage = targetPage.Substring(5); // ?404;
    	}
    	else
    	{
    	     if(-1 != targetPage.IndexOf("errorpath="))
    		 targetPage = targetPage.Substring(14); // aspxerrorpath=
    	     else
    		targetPage = targetPage.Substring(4); // 404;
    	}
    }				

    string upperTarget = targetPage.ToUpper();
    if((-1 == upperTarget.IndexOf(".ASPX")) && (-1 != upperTarget.IndexOf(".ASP")))
    {
    	//this is a request for an .ASP page - permanently redirect to .aspx
    	targetPage = upperTarget.Replace(".ASP", ".ASPX");
    	//issue 301 redirect
    	Response.Status = "301 Moved Permanently"; 
    	Response.AddHeader("Location",targetPage);
    	Response.End();
    }

    if(-1 != upperTarget.IndexOf("ORDER"))
    {
                //going to old order page -- forward to new page
               Response.Redirect(WebRoot + "/order.aspx");
           Response.End();
    }

这篇关于404页显示请求的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆