在URL部分中输入实例名称,但根据Web.config文件中的扩展名阻止对文件的访问时,如何导航到index.php?

我具有以下要求:在IIS的Web.config文件中使用以下几行来阻止基于扩展名的文件的访问。

<system.webServer>
   <security>
      <requestFiltering>
         <fileExtensions allowUnlisted="false">
            <add fileExtension=".php" allowed="true" />
            <add fileExtension=".js" allowed="true" />
            <add fileExtension=".css" allowed="true" />
            <add fileExtension=".png" allowed="true" />
            <add fileExtension=".jpg" allowed="true" />
            <add fileExtension=".gif" allowed="true" />
            <add fileExtension=".jar" allowed="true" />
         </fileExtensions>
      </requestFiltering>
   </security>
</system.webServer>

但是这些行阻止了应用程序导航到index.php(主页)。如何解决这个问题?

snowcarangid 回答:在URL部分中输入实例名称,但根据Web.config文件中的扩展名阻止对文件的访问时,如何导航到index.php?

按照Lex Li的方法可以满足您的要求。此外,URL重写可以提供另一种方法来基于{PATH_INFO}变量阻止所有未列出的扩展名。

 <rule name="rewrite" enabled="true" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{PATH_INFO}" pattern="\.(js|php|css|png|jpg|gif|jar)$" negate="true" />
                    </conditions>
                    <action type="AbortRequest" />
                </rule>
本文链接:https://www.f2er.com/2792474.html

大家都在问