【问题标题】:My URL isn't being rewritten using the WEB CONFIG我的 URL 没有使用 WEB CONFIG 重写
【发布时间】:2020-02-19 14:17:35
【问题描述】:

当前网址:

localhost:62859/review.aspx?c=football&t=Liverpool

我要达到的网址

本地主机:62859/足球/利物浦

我用来尝试实现此目的的网络配置中的代码

<rule name="Rewrite Review">
  <match url="^review/([0-9]+)/([_0-9a-z-]+)" />
  <action type="Rewrite" url="?c={R:1}&amp;t={R:2}" />
</rule>

这只是返回一个 404 响应。我做错了什么?

【问题讨论】:

  • 你了解 URL 重写的作用吗? localhost:62859/football/Liverpool 是您应该向用户显示的内容(即在您的 HTML 中输出); localhost:62859/review.aspx?c=football&amp;t=Liverpool 是服务器/应用程序所期望的。您的&lt;match /&gt; 模式应该尝试匹配用户看到的内容(因为这将被发送回服务器),然后&lt;action /&gt; 应该指定如何将匹配的文本转换为服务器期望的内容。你的&lt;action /&gt; 看起来不错;你的&lt;match /&gt; 需要工作。该模式与 URL 中的字符无关。

标签: c# asp.net web-config


【解决方案1】:
<rule name="rewrite">
  <match url="^([^/]+)/([^/]+)?$" />
<action type="Rewrite" url="/review.aspx?c={R:1}&amp;t={R:2}" appendQueryString="false" />
</rule>

工作。

【讨论】:

    猜你喜欢
    • 2013-11-19
    • 1970-01-01
    • 1970-01-01
    • 2018-03-26
    • 2015-05-14
    • 2011-06-03
    • 1970-01-01
    • 2013-11-14
    • 1970-01-01
    相关资源
    最近更新 更多