我在IIS 8上的ASP.NET(4)中有一个新站点。
我需要将以前网站的旧版php链接(具有查询字符串)重定向到新页面(现在有一个友好的URL)。许多重定向的PHP页面都是相同的,只有查询字符串发生了变化(例如id = 6)。
例如 site.com/page.php?id=6> site.com/an-article site.com/page.php?id=7> site.com/another-article
最简单/最快捷的方法是什么?
答案 0 :(得分:0)
您将要构建新的.net链接并使用该链接向用户发送HTTP 301:
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $url);
die();
“url”变量是您网站的新翻译网址。
答案 1 :(得分:0)
管理你的老&数据库中的新链接。将OldLink,NewLink存储在数据库中。并且用于加载App_start中缓存中的所有列表,以便为所有后续请求访问。
您需要为此重写URL。
您需要在global.asax
中工作在application_beginrequest方法中编写你的url重写逻辑
e.g。
string aspxurl = string.Empty;
string querystring = string.Empty;
string[] strTmpQuery = System.Web.HttpContext.Current.Request.RawUrl.Split('?');
if(strTmpQuery[0].Endswith(".php"))
{
aspxurl = strTmpQuery[0].Substring(0,strTmpQuery[0].Length-4) + ".aspx";
}
if(strTmpQuery.Length>1 && strTmpQuery[1].Trim() != "")
{
querystring = strTmpQuery[1];
}
System.Web.HttpContext.Current.RewritePath(aspxurl, "", querystring);
注意:您必须调整web.config以便IIS将对PHP文件的请求发送到.net引擎。寻找HttpModule / HttpHandler进行网址重写