0

我正在尝试从基于窗口的托管中隐藏 .php 扩展名。

我正在尝试使用 web.config

<?xml version="1.0" encoding="UTF-8"?>
 <configuration>
  <system.webServer>
    <rewrite>
     <rule name="hide .php extension" stopProcessing="true">
      <match url="(.*)" />
       <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
       </conditions>
     <action type="Rewrite" url="{R:1}.php" />
    </rule> 
  </rewrite>
 </system.webServer>
</configuration>

它显示404错误,请提出问题所在。

谢谢你。

4

1 回答 1

0

我也在 Windows IIS 环境上开发 PHP,你的规则在我的环境中工作得很好。检查我的 web.config 这对我来说非常有效,也许这对你有帮助;

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.web>
        <globalization fileEncoding="UTF-8" responseEncoding="UTF-8" culture="tr-TR" uiCulture="tr-TR" />
    </system.web>
    <system.webServer>
        <defaultDocument>
            <files>
                <add value="index.php" />
            </files>
        </defaultDocument>
        <rewrite>
            <rules>
                <rule name="hide .php extension" stopProcessing="true">
                  <match url="(.*)" />
                   <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                   </conditions>
                 <action type="Rewrite" url="{R:1}.php" />
                </rule>
        </rewrite>
        <handlers>
            <add name="PHP" path="*.php" verb="*" modules="FastCgiModule" scriptProcessor="C:\php\php-cgi.exe" resourceType="File" />
        </handlers>
    </system.webServer>
</configuration>

PS:如果这对您不起作用,您可以检查Event Viewer您的 Windows 操作系统

于 2016-01-30T09:48:52.927 回答