【问题标题】:Hide .php extension from window server hosting从窗口服务器托管隐藏 .php 扩展名
【发布时间】:2016-01-30 17:48:52
【问题描述】:

我正在尝试从基于窗口的托管中隐藏 .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错误,请指出问题出在哪里。

谢谢。

【问题讨论】:

  • 这条规则适用于我的环境。我认为它与您的重写规则无关。你检查过事件日志吗?你的 php 处理程序如何为 iis 工作,它应该是 fast-cgi 吗?

标签: php iis url-rewriting web-config window-server


【解决方案1】:

我也在 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 操作系统

【讨论】:

  • 感谢您的回复,当我运行您给定的代码时,我发现错误“HTTP 错误 500.19 - 内部服务器错误”
  • 您的服务器是共享主机吗?你能检查这个链接的结果代码吗:support.microsoft.com/en-us/kb/942055
  • 我认为是 IIS 8.0
猜你喜欢
  • 2011-01-08
  • 1970-01-01
  • 2021-01-23
  • 2019-01-02
  • 2012-03-06
  • 1970-01-01
  • 2018-03-14
  • 2011-10-22
  • 2014-08-08
相关资源
最近更新 更多