php - azure应用程序url重写中的.htaccess文件

标签 php azure iis url-rewriting

我有一个用 Php Angular mySql 开发的单页应用程序。它使用rest api 类从mysql 数据库获取数据。

应用程序在与 cPanel (linux) 的共享主机中运行良好。我复制了 Azure 应用程序服务中的文件,但无法使其正常工作。我收到以下消息:

The page cannot be displayed because an internal server error has occurred.

我知道它正在运行 IIS,而 IIS 不支持重写 url 的 .htaccess 文件。

.htaccess 的内容是:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ api.php?x=$1 [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ api.php [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^(.*)$ api.php [QSA,NC,L]   
</IfModule>

如果已经做了一些研究并将 .htaccess 更改为 web.config 但仍然无法使其工作。

我的 web.config 是:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<configSections>
    <sectionGroup name="system.webServer">
        <sectionGroup name="rewrite">
            <section name="rewriteMaps" overrideModeDefault="Allow" />
            <section name="rules" overrideModeDefault="Allow" />
        </sectionGroup>
    </sectionGroup>
</configSections>

<system.webServer>
    <security>

    </security>
    <directoryBrowse enabled="true" />
    <caching>
        <profiles>
            <add extension=".php" policy="DisableCache" kernelCachePolicy="DisableCache" />
            <add extension=".html" policy="CacheForTimePeriod" kernelCachePolicy="CacheForTimePeriod" duration="14:00:00:00" />
        </profiles>
    </caching>
    <rewrite>
    <rules>
    <rule name="rule 1K" stopProcessing="true">
        <match url="^(.*)$"  ignoreCase="true" />
        <action type="Rewrite" url="/php/services/api.php?x={R:1}"  appendQueryString="true" />
    </rule>

        </rules>
    </rewrite>
    <defaultDocument>
        <files>
            <remove value="index.php" />
            <add value="index.php" />
        </files>
    </defaultDocument>



</system.webServer>

最佳答案

根据你的web.config的内容,所有的请求都会被重写到php/services/api.php根目录下的脚本。那么您能否确保路径中存在该脚本。

另外,根据您收到的错误消息,通常,当我们收到此消息时,这意味着您的服务器上的代码有问题。

根据我的经验,也许您错过了 PHP 脚本中所需的任何依赖项。您可以登录Web应用程序的KUDU控制台站点来检查应用程序的完整性。 Kudu 控制台站点的 URL 应为 https://<your_site_name>.scm.azurewebsites.net .

如有任何更新,请随时告诉我。

关于php - azure应用程序url重写中的.htaccess文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37763555/

相关文章:

c# - 具有多个筛选器的 Azure 搜索服务

azure - 如何使用服务托管标识通过 Terraform 在 Azure 中配置资源

c# - 如何在 IIS 上运行的 dotnet 核心应用程序中获得可见性/调试高内存使用率

c# - 当页面呈现超时时会发生什么?

php - 在ubuntu容器上添加mysql数据库

php - Yii 中的 CMenu 样式

php - 将变量传递给 JSON 数据的远程 PHP 文件

php - 与 src 处于同一级别的文件夹的 PSR-4 命名空间约定

c# - ASP.NET MVC 如何将应用程序从 ASP.NET Identity 转换为 Azure AD

asp.net - 我的机器 key 是自动生成的还是隔离的?