【发布时间】:2016-10-12 07:48:58
【问题描述】:
我有一个用 Php angular mySql 开发的单页应用程序。它使用一个 rest api 类从 mysql db 中获取数据。
应用程序在与 cPanel (linux) 的共享主机中运行良好。我复制了 Azure 应用服务中的文件,但无法正常工作。我收到以下消息:
由于发生内部服务器错误,页面无法显示。
我知道它正在运行 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>
【问题讨论】:
-
将你的php api应用程序放到根目录的
/php/services/文件夹中?如果您删除web.config并直接浏览php api应用程序,它是否可以正常工作?
标签: php azure iis url-rewriting