![](/img/trans.png)
[英]Why do I get a 500 when I add a rewrite rule to my Web.config in Azure?
[英]Rewrite rule “URL as parameter” in IIS web.config (returns error 500)
我使用标志[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.config在http://localhost/dir/web.config下 ...
结果:开放的http://本地主机/目录/和HTTP://本地主机/目录/示例执行的index.php正确,但访问HTTP://本地主机/目录/ I / HTTP://example.org返回错误500 The page cannot be displayed because an internal server error has occurred.
预期: http:// localhost / dir / i / http://example.org必须使用$_GET['i']
值dir/i/http://example.org
http://example.org执行index.php
看来IIS不允许在URL中使用:/
...是否有任何解决方法/修复程序?
像http://www.htaccesstowebconfig.com这样的工具无法正确转换.htaccess,非常感谢您的帮助/建议。
我找到响应包含:/
URL并返回多个斜杠值/查询://...
(示例URL 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
值,例如/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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.