我试图从基于 Windows 的托管中隐藏.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错误,请建议问题出在哪里。
我也在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:如果这对您不起作用,您可以检查您的 Windows 操作系统的Event Viewer