我正在 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&maincategory=$1&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.
发布评论
评论(2)
问题在于 IIS7 请求过滤器拒绝包含 + 字符的 URL。解决方案是将以下内容添加到您的 Web.config:
有关更多详细信息: 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:
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.
这对我来说似乎很奇怪,因为你的正则表达式也匹配“+”字符。也许问题是因为正则表达式中的第一个字符,即您正在使用的字符串“^”的开头。也许在生产服务器上您会获得绝对 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.