簡體   English   中英

在IIS web.config中重寫規則“ URL作為參數”(返回錯誤500)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM