【问题标题】:Rewrite .aspx Url to .asp Url [SEO issues]将 .aspx 网址重写为 .asp 网址 [SEO 问题]
【发布时间】:2014-02-13 05:52:20
【问题描述】:

大家好,我正在做一个项目,我有一个 .aspx 页面 (index.aspx) 出于某些 SEO 原因。 seo 家伙希望我将 index.aspx url 显示为 index.asp

连页面中的链接也应该写成index.asp

我已经写了这条规则,但它说找不到文件,因为它实际上没有找到实际的 .asp 文件.. 所以我只想将 url 路径从 aspx 重写为 asp

<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>

谢谢

【问题讨论】:

    标签: asp.net .net url-rewriting


    【解决方案1】:

    这种方式很简单,也很用心。这样我们就可以重写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");
      }
    }
    

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

    【讨论】:

    • 我尝试了您的代码,但它显示为 404 Error not found.
    猜你喜欢
    • 2015-03-14
    • 2011-03-11
    • 1970-01-01
    • 1970-01-01
    • 2018-07-31
    • 2016-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多