我使用标记[B]
管理Apache .htaccess的"URL作为参数"
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{THE_REQUEST} s/+(S+)
RewriteRule (.*) index.php?i=%1 [B,L]
不幸的是,我不知道如何在IIS web.config中做同样的事情
<configuration>
<system.webServer>
<defaultDocument enabled="true">
<files>
<clear/>
<add value="index.php"/>
</files>
</defaultDocument>
<modules runAllManagedModulesForAllRequests="true"/>
<rewrite>
<rules>
<rule name="rule" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?i={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
以web为例。
结果:打开http://localhost/dir/和http://localhost/dir/example可以正确执行index.php,但是访问http://localhost/dir/i/http://example.org返回错误500 The page cannot be displayed because an internal server error has occurred.
期望: http://localhost/dir/i/http://example.org必须执行index.php的$_GET['i']
值dir/i/http://example.org
似乎IIS不允许在URL :/
中使用…有什么解决方法/修复吗?
像http://www.htaccesstowebconfig.com这样的工具不能正确转换。htaccess,您的帮助/建议将非常感谢。
我找到响应包含:/
和返回多个斜杠值/查询://...
(示例URL http://localhost/dir/i/http://example.org)的URL的唯一方法是使用UNENCODED_URL
;休耕制答:
<rule name="Index" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?i={UNENCODED_URL}" appendQueryString="true" />
</rule>
注意,它将返回以/
开头的值,如/dir/i/http://example.org
。
允许使用特殊符号,如
<system.web>
<httpRuntime requestValidationMode="2.0" requestPathInvalidCharacters="" relaxedUrlToFileSystemMapping="true" AllowRestrictedChars="1" UrlSegmentMaxLength="2048" />
<pages validateRequest="false" />
</system.web>
<security>
<requestFiltering allowDoubleEscaping="false" />
</security>
没有给任何好处来解决这个问题(没有必要)。
Update:在本地Windows 10机器上工作正常,但在Azure服务器上仍然返回错误500。不知道为什么。
ModuleName IIS Web Core
Notification BEGIN_REQUEST
HttpStatus 500
HttpReason Internal Server Error
HttpSubStatus 19
ErrorCode The specified path is invalid.
(0x800700a1)
ConfigExceptionInfo \?D:homesitewwwrootihttp:web.config ( 0) :Cannot read configuration file