IIS web.config问题

时间:2019-05-06 00:22:17

标签: php .htaccess iis url-rewriting web-config

我最近从RackSpace托管的专用服务器上的LAMP切换到Azure Webapp。我有一个PHP应用程序,该应用程序的编写方式并不总是在重定向的末尾包含.php,并且希望尽可能在URL中隐藏.php。

使用.htaccess来访问web.config转换器,我想到了这一点,但是我在任何页面上都遇到了内部服务器错误,请访问... .php。如果删除web.config,则可以通过在URL中强制使用.php来访问页面。

  <?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
<rewrite>
    <rule name="hide php extension" stopProcessing="true">
        <match url="^(.*)/$" />
        <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
        </conditions>
        <action type="Rewrite" url="{R:1}.php" />
    </rule>
</rules>
</rewrite> 
  </system.web>
</configuration>

我想念什么吗?我认为这很容易,但显然这超出了我的能力范围。我已经尝试过这里发布的各种规则,但是对IIS的了解还不足以编写我自己的规则。

1 个答案:

答案 0 :(得分:0)

您可以尝试在web.config文件中添加以下规则:

 <rule name="Redirect .php extension" enabled="true" stopProcessing="false">
  <match url="^(.*).php$" ignoreCase="true" />
<conditions logicalGrouping="MatchAny">
  <add input="{URL}" pattern="(.*).php$" ignoreCase="false" />
</conditions>
  <action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>

<rule name="hide .php extension" enabled="true" stopProcessing="true">
  <match url="^(.*)$" ignoreCase="true" />
<conditions>
  <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
  <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  <add input="{REQUEST_FILENAME}.php" matchType="IsFile" />
</conditions>
  <action type="Rewrite" url="{R:0}.php" />
</rule>

enter image description here

关于, 贾帕(Jalpa)

相关问题