【问题标题】:.htaccess file in azure app url rewriting天蓝色应用程序 url 重写中的 .htaccess 文件
【发布时间】: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


【解决方案1】:

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

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

根据我的经验,您可能会错过 PHP 脚本中所需的任何依赖项。您可以登录 Web 应用程序的 KUDU 控制台站点来检查应用程序的完整性。 Kudu 控制台的 URL 应该是https://&lt;your_site_name&gt;.scm.azurewebsites.net

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

【讨论】:

    猜你喜欢
    • 2018-07-03
    • 1970-01-01
    • 2015-09-25
    • 1970-01-01
    • 2014-03-24
    • 1970-01-01
    • 2011-04-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多