简体   繁体   中英

IIS web.config Issue

I recently switched from LAMP on a dedicated server hosted on RackSpace to a Azure Webapp. I have a PHP application that was wrote in a way that doesn't always include the .php at the end of the redirects, and wants to hide the .php in the URL whenever possible.

Using a .htaccess to web.config convertor I came up this, but I get an internal server error on ANY page i go to... .php or not. If I remove the web.config I can access the pages by forcing the .php in the url.

  <?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>

Am I missing something? I would think that it would be easy, but clearly it is beyond my capabilities. I've played around with various rules posted here, but do not know enough about IIS yet to write my own rules.

You could try to add below rule in your web.config file:

 <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>

在此输入图像描述

Regards, Jalpa

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM