我有一个用 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/