重写规则" URL作为参数"在IIS web.config中(返回错误500)

时间:2016-10-05 08:42:37

标签: azure mod-rewrite iis web-config

我管理&#34; URL作为参数&#34; Apache .htaccess使用标记cout << "1"; Sleep(500); system("cls"); cout << "2"; Sleep(500); system("cls"); cout << "3"; Sleep(500); system("cls"); cout << "4"; Sleep(500); system("cls"); cout << "5"; Sleep(500); system("cls"); cout << "6"; //goes until 100

[B]

不幸的是,无法弄清楚如何在IIS web.config

中执行相同操作
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{THE_REQUEST} \s/+(\S+)
RewriteRule (.*) index.php?i=%1 [B,L]

让我们说web.config位于http://localhost/dir/web.config ...

结果:打开http://localhost/dir/http://localhost/dir/example正确执行index.php,但访问 http://localhost/dir/i/http://example.org会返回错误500 {{1 }}

预期: http://localhost/dir/i/http://example.org必须执行<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> 值为The page cannot be displayed because an internal server error has occurred.的index.php

似乎IIS不允许在URL $_GET['i']中使用...任何解决方法/修复方法?

http://www.htaccesstowebconfig.com这样的工具无法正确转换.htaccess,我们非常感谢您的帮助/建议。

1 个答案:

答案 0 :(得分:0)

我找到回复包含:/的网址并返回多个斜杠值/查询://...(示例网址http://localhost/dir/i/http://example.org)的方法的唯一方法是使用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>

没有给出任何好处以解决问题(不需要它)。

更新:它在本地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:\home\site\wwwroot\i\http:\web.config ( 0) :Cannot read configuration file