在 IIS 上的 Windows 专用服务器上托管 php 文件时

如果没有文件扩展名“.php”,我无法查看托管在 IIS(Windows 专用服务器 2016)上的文件

前任:

下面的 URL 产生了正确的输出: http ://example.com/test/test.php

虽然这个版本说: http ://example.com/test/test

“服务器错误 404 - 找不到文件或目录。您要查找的资源可能已被删除、名称已更改或暂时不可用。”

选中并启用目录浏览,FastCGI,我们可以访问其他文件,例如图像,pdf,它们是相同的链接。

通过链接寻找将“.htaccess”转换为“web.config”的可能解决方案,清除缓存并刷新DNS,但问题仍然存在。

https://docs.microsoft.com/en-us/iis/application-frameworks/install-and-configure-php-applications-on-iis/translate-htaccess-content-to-iis-webconfig


精慕HU
浏览 173回答 1
1回答

潇湘沐

由于 IIS 中没有 PHP-extensionless 处理程序,因此 IIS 在默认情况下将永远无法处理没有扩展的 PHP。要解决此问题,您必须使用 URL 重写模块将无扩展名的 url 重写为 .php url。例如,您可能需要将 test\test 重写为 test\test.php。所以当你输入 test\test 时,服务器会返回 test.php 的内容。<rule name="rewrite">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <match url="(.*)" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <conditions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <add input="{REQUEST_URI}" pattern="^/test/([a-zA-Z0-9]+)$" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </conditions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <action type="Rewrite" url="{C:0}.php" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </rule>因为我不确定需要重写哪个 URL。您可以修改此规则。
打开App,查看更多内容
随时随地看视频慕课网APP