gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 14:06:05 26 4
gpt4 key购买 nike

我有许多由 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com