使用 UrlRewritingNet 进行 URL 重写失败,并显示 + URL 中的字符

发布于 2024-09-25 06:06:13 字数 975 浏览 5 评论 0 原文

我正在 Umbraco 中使用 UrlRewritingNet 对产品和类别 URL 进行一些基本的 URL 重写。在我的本地计算机(Visual Studio dev-webserver)和我们的内部开发服务器(带有 ISS 7、32 位的 Window Server 2008)上一切都很好。但它在生产服务器(带有 IIS 7(64 位)的 Window Server 2008 R2)上失败。现象是没有触发重写规则。服务器只是给我一个 404 错误。

重写规则如下所示:

<add name="CategoryRewrite"
     virtualUrl="^/products/(.*)/(.*).aspx"
     rewriteUrlParameter="ExcludeFromClientQueryString"
     destinationUrl="~/default.aspx?umbPage=1&amp;maincategory=$1&amp;subcategory=$2"
     ignoreCase="true"/>

URL 如下所示 - 这不起作用:

http://example.net/products/category+name/sub+category.aspx

如果我将 URL 更改为以下内容,则它在所有 3 个环境中都有效:

http://example.net/products/category%20name/sub%20category.aspx

很明显,当 + 为用于空格字符。但我必须承认,我只能弄清楚为什么正则表达式仅在 Windows 2008 R2 服务器上失败。

我正在寻找有关 Windows Server 2008 R2 和其他 2 个环境之间的差异的见解。我应该寻找什么?

我已确认 System.Web.RegularExpressions.dll 在服务器上是相同的版本。

I'm using UrlRewritingNet in Umbraco to do some basic URL rewriting of product and category URLs. Everything is fine on my local machine (Visual Studio dev-webserver) and on our internal development server (Window Server 2008 with ISS 7, 32 bit). But it fails on the production server, which is Window Server 2008 R2 with IIS 7 (64 bit). The symptom is that the rewrite rule is not triggered. The server simply gives me an 404 error.

The rewriting rule looks like this:

<add name="CategoryRewrite"
     virtualUrl="^/products/(.*)/(.*).aspx"
     rewriteUrlParameter="ExcludeFromClientQueryString"
     destinationUrl="~/default.aspx?umbPage=1&maincategory=$1&subcategory=$2"
     ignoreCase="true"/>

The URL looks like the following - this doesn't work:

http://example.net/products/category+name/sub+category.aspx

If I change the URL to the following it works in all 3 environments:

http://example.net/products/category%20name/sub%20category.aspx

It is clear that the regex in the virtualUrl attribute fails when the + is used for the space character. But I must admit, that I can figure out why the regex fails only on the Windows 2008 R2 server.

I'm looking for insights on what differences between the Windows Server 2008 R2 and the other 2 environments. What should I look for?

I have confirmed that the System.Web.RegularExpressions.dll is the same version on the servers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你怎么这么可爱啊 2024-10-02 06:06:14

问题在于 IIS7 请求过滤器拒绝包含 + 字符的 URL。解决方案是将以下内容添加到您的 Web.config:

<configuration>
 <system.webServer>
  <security>
   <requestFiltering allowDoubleEscaping="true" />
  </security>
 </system.webServer>
</configuration> 

有关更多详细信息: http://blogs.iis.net/thomad/archive/2007/12/17/iis7-rejecting-urls-containing.aspx

一位同事想到了运行该网站的好主意在他自己的 IIS 上。然后错误被进一步定义为 404.11,从此解决方案就很简单了。

The problem is that the IIS7 request filter rejects URLs containing + characters. The solution is add the following to you Web.config:

<configuration>
 <system.webServer>
  <security>
   <requestFiltering allowDoubleEscaping="true" />
  </security>
 </system.webServer>
</configuration> 

For further details: http://blogs.iis.net/thomad/archive/2007/12/17/iis7-rejecting-urls-containing.aspx

A coworker got the bright idea to run the website on his own IIS. And then the error was further defined as a 404.11, and from there on a solution was simple.

蓝眼泪 2024-10-02 06:06:14

这对我来说似乎很奇怪,因为你的正则表达式也匹配“+”字符。也许问题是因为正则表达式中的第一个字符,即您正在使用的字符串“^”的开头。也许在生产服务器上您会获得绝对 URL,而在开发环境服务器上您会获得传递到重写模块的相对 URL。

That seems strange to me because your regex matches also '+' characters. Maybe the problem is because of the first character in the regex, beginning of string '^' that you are using. Maybe on the production server you get an absolute URL and on your dev environment server a relative URL passed into the rewriting module.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文