【问题标题】:What will be the URL Rewriting rule for this?对此的 URL 重写规则是什么?
【发布时间】:2012-09-25 05:05:39
【问题描述】:

我在 Godaddy 的 Windows 主机上有一个静态 Web 应用程序。

在我的应用程序中,我有如下 URL:

http://MyDomain.com/?page_id=18
http://MyDomain.com/?page_id=19
http://MyDomain.com/?page_id=20

我希望重写后的 URL 是这样的:

http://MyDomain.com/microsoft-cloud-crm-for-small-business
http://MyDomain.com/online-development
http://MyDomain.com/small-development

那么 web.config 文件中的 URL 重写规则是什么?

编辑:

<configuration>
<system.webServer>
<httpErrors errorMode="Detailed" />
<asp scriptErrorSentToBrowser="true"/>
<rewrite>
    <rules>
    <rule name="Rewrite url" stopProcessing="true">
        <match url="^\?page_id=18" />
                    <action type="Rewrite" url="microsoft-cloud-crm-for-small-business" />
    </rule>
    <rule name="Rewrite url1">
        <match url="^\?page_id=21" />
                    <action type="Rewrite" url="Implementation" />
    </rule>
    </rules>
</rewrite>
</system.webServer>
<system.web>
    <customErrors mode="Off"/>
    <compilation debug="true"/>
</system.web>
</configuration>

提前致谢。

【问题讨论】:

    标签: asp.net url-rewriting


    【解决方案1】:
    <rewrite>
    <rules>
    <rule name="Rewrite url">
        <match url="^?page_id=18" />
        <action type="Rewrite" url="custom-development.html" />
        </rule>
    </rules>
    </rewrite>
    

    【讨论】:

    • 您可能需要考虑使用 RewriteMap,这样您就不需要写出每个正则表达式。
    • 您需要获取详细的错误消息。见support.godaddy.com/help/article/3430/…
    • The expression "^?page_id=18" contains a repeat expression (one of '*', '?', '+', '{' in most contexts) not preceded by an expression.
    • 对不起,伙计。把 '?' 放在一个 '\' 中。 ''
    • 好的..错误消失了...但现在什么都没有发生..它没有重写为MyDomain.com/custom-development.html
    【解决方案2】:

    您好,实际上我没有使用 .html 扩展 url 重写。我正在使用不带扩展名的 url 重写,你说的是哪个 url 我在我的项目中为该 url 创建了一个规则,它在下面

    <add name="test"  virtualUrl="^~/test-page/([0-9,a-z,A-Z,_,-]*)"
      rewriteUrlParameter="ExcludeFromClientQueryString"
      destinationUrl="~/test.aspx?cid=$1"
      ignoreCase="true" />
    

    我认为这会对你有所帮助...

    【讨论】:

      【解决方案3】:

      如果您在 .Net 4.0 版中使用 asp.net,您也可以在 Web 表单项目中获得 RouteCollection 的好处。

      使用它,您可以轻松地将您的 URL 映射到特定的导航规则。

      例如,在您的情况下,如果“microsoft-cloud-crm-for-small-business”与任何表中的名称相同,您可以将以下代码放入 global.asax...

       routes.MapPageRoute(
                     "ViewPageDetail",               // Route name
                     "/{*CategoryName}",  // Route URL
                     "~/PageDetail.aspx"      // Web page to handle route
                  );
      

      然后在您的页面加载中,您可以有类似以下的内容。

      string productName = Page.RouteData.Values["CategoryName"] as string;
      

      并使用产品名称获取产品详细信息。

      通过这种方式,您可以通过正在呈现的逻辑和页面实现更好的代码完整性。这是用于 SEO 的 asp.net 4.0 中的新内容之一。

      can check 以便更好地理解。

      谢谢

      【讨论】:

        猜你喜欢
        • 2014-01-06
        • 1970-01-01
        • 1970-01-01
        • 2018-08-11
        • 2014-02-03
        • 2014-04-14
        • 2011-06-18
        • 1970-01-01
        • 2018-11-21
        相关资源
        最近更新 更多