How to remove .php extension on Azure PHP Web App

ぃ、小莉子 提交于 2019-12-13 03:56:23

问题


How do I remove the .php extension on a Azure PHP Web App ?

using at htaccess file with the following, does NOT work

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

Ideas ?


回答1:


Azure Web Apps use IIS to host your application. The best equivalent of Apache's .htaccess system is actually using web.config file to handle URL rewrite in IIS.

For example, you can just put the following web.config file into your web app's root folder to hide .php extension.

Referece:

https://www.saotn.org/iis-url-rewrite-hide-php-extension.

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
  <system.webServer>
    <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>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

Hope it helps.



来源:https://stackoverflow.com/questions/55757746/how-to-remove-php-extension-on-azure-php-web-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!