iis - 无法获取 IIS URL 重写规则以修复 URL 中的 %3F 和 %3D

标签 iis url-rewriting

我有许多由 Google 网站管理员工具报告的入站链接,其中包含导致 404 错误的实体。我想创建一些可以与 IIS 一起使用的 url 重写规则来处理这个问题。这些规则需要在任何页面上工作,因为一些包含实体的链接可能是几个文件夹深,并且是 index.php 以外的文件。

例如重写规则应该能够处理:

www.mysite.com/index.php%3Fpage%3Dtest

www.mysite.com/folder/somepage.php%3Fvariable%3Dtest

并将它们转换为:

www.mysite.com/index.php?page=test

www.mysite.com/folder/somepage.php?variable=test

我尝试创建自己的规则,但并没有走多远。我发现 Apache 的规则可以处理这个问题,但是使用 IIS 导入规则工具导入它们不起作用。

以下是适用于 Apache 的内容(现在我们只需要一个 IIS 版本):

# If THE_REQUEST contains a URL-path with a percent-encoded "?" and/or a query string with one
# or more specific percent-encoded characters, and we're not already in the process of fixing
# it, then copy the client-requested URL-path-plus-query-string into the "MyURI" variable.
RewriteCond %{ENV:MyURI}>%{THE_REQUEST} ^>[A-Z]+\ /([^\ ]+)\ HTTP/
RewriteCond %1 ^([^?]*\?([^%]*(\%(25)*([^3].|.[^D]))*)*\%(25)*3D.*)$ [NC,OR]
RewriteCond %1 ^([^?]*\?([^%]*(\%(25)*([^2].|.[^6]))*)*\%(25)*26.*)$ [OR]
RewriteCond %1 ^(([^%]*(\%(25)*([^3].|.[^F]))*)*\%(25)*3F.*)$ [NC]
RewriteRule ^. - [NE,E=MyURI:%1]
#
# If any encoded question mark is present in the client-requested URI, and
# no unencoded question mark is present, replace the first encoded question
# mark, queue up a redirect, and then re-start mod_rewrite processing
RewriteCond %{ENV:MyURI} ^[^?]+$
RewriteCond %{ENV:MyURI} ^(([^%]*(\%(25)*([^3].|.[^F]))*)*)\%(25)*3F(.*)$ [NC]
RewriteRule ^. - [NE,E=MyURI:%1?%7,E=QRedir:Yes,N]
#
# If any encoded "=" sign follows the "?", replace it, queue
# up a redirect, and re-start mod_rewrite processing
RewriteCond %{ENV:MyURI} ^([^?]*\?([^%]*(\%(25)*([^3].|.[^D]))*)*)\%(25)*3D(.*)$ [NC]
RewriteRule ^. - [NE,E=MyURI:%1=%7,E=QRedir:Yes,N]
#
# If any encoded ampersand follows the "?", replace it, queue
# up a redirect, and then re-start mod_rewrite processing
RewriteCond %{ENV:MyURI} ^([^?]*\?([^%]*(\%(25)*([^2].|.[^6]))*)*)\%(25)*26(.*)$
RewriteRule ^. - [NE,E=MyURI:%1&%7,E=QRedir:Yes,N]
#
# If we get here, there are no more percent-encoded characters which can
# and should be replaced by the rules above, so do the external redirect
RewriteCond %{ENV:QRedir} =Yes [NC]
RewriteRule ^. http://www.example.com/%{ENV:MyURI} [NE,R=301,L]

这至少让我们知道在编写 IIS url 重写规则时需要考虑什么。

最佳答案

这条规则对你有用:

<rule name="3f and 3d redirect">
    <match url="(.*)(\?|\=)(.*)" />
    <action type="Redirect" url="{R:0}" />
</rule>

关于iis - 无法获取 IIS URL 重写规则以修复 URL 中的 %3F 和 %3D,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13749307/

相关文章:

c# - 如何使用服务器端 Blazor 启用 Windows 身份验证

wcf : Service + Client in same solution, 如何调试?我不想同时运行 2 个版本的 VS 2010

laravel - "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable"Azure 上的 Laravel

apache - RewriteCond 以任意顺序匹配查询字符串参数

apache - 将 URI/foo 映射到 Tomcat/

java - Java Web 应用程序的特殊 URL 格式

c# - 为什么 ASP.NET 页面在 IE 上呈现的速度比 Chrome 或 FF 快?

asp.net-mvc - 如何在 asp.net mvc、web.config 文件中为特定位置设置 maxRequestLength 和 maxAllowedContentLength?

php - Apache 重写查询字符串(复选框数组)

redirect - 如何重定向并删除 URL 中的 .html 扩展名?