将.aspx Url重写为.asp Url [SEO问题]

时间:2014-02-13 05:52:20

标签: asp.net .net url-rewriting

我们正在开展一个项目,我有一个.aspx页面(index.aspx) 出于某些SEO的原因。 seo们希望我将index.aspx url显示为index.asp

即使页面中的链接也应该说index.asp

我写过这个规则,但它说文件找不到,因为它实际上找不到实际的.asp文件..所以我只想重写从aspx到asp的url路径

<rule name="RewriteASPX">
  <match url="(.*)" />
  <conditions logicalGrouping="MatchAll">
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  </conditions>
  <action type="Rewrite" url="{R:1}.asp" />
</rule>

谢谢

1 个答案:

答案 0 :(得分:0)

这种非常简单的方式,非常充分使用。通过这种方式,我们可以重写N个页面,不需要额外的服务器配置。只有您必须使用Application_BeginRequest事件。在此事件中,使用Context.RewritePath方法设置将在代码后面内部执行的URL。这是代码:

void Application_BeginRequest(object sender, EventArgs e)
{
 // Get the current path
 string CurrentURL_Path = Request.Path;

 if (CurrentURL_Path.EndsWith("x"))
     CurrentURL_Path = CurrentURL_Path.Remove(CurrentURL_Path.Length - 1);
   {
     HttpContext MyContext = HttpContext.Current;
     MyContext.RewritePath("CurrentURL_Path");
  }
}

注意:我没有发送此代码。

相关问题