如何在Azure PHP Web App上删除.php扩展名 [英] How to remove .php extension on Azure PHP Web App

查看:67
本文介绍了如何在Azure PHP Web App上删除.php扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Azure PHP Web应用程序上删除.php扩展名?

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

在htaccess文件中使用以下命令将不起作用

using at htaccess file with the following, does NOT work

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

想法?

推荐答案

Azure Web Apps使用IIS托管您的应用程序.Apache的.htaccess系统的最佳替代品实际上是使用web.config文件来处理IIS中的URL重写.

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.

例如,您可以将以下web.config文件放入Web应用程序的根文件夹中以隐藏.php扩展名.

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

参考:

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>

希望有帮助.

这篇关于如何在Azure PHP Web App上删除.php扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆