Azure 上的 Yii2 webapp 不工作

Yii2 webapp on Azure not working

我有一个分别基于 Yii + Yii2 框架构建的网站 + 服务应用程序。 我尝试在 Azure http://xxxxxx.azurewebsites.net/ 上托管它。基于 Yii1 构建的网站运行良好。基于 Yii2 端点的服务返回 404。服务正在本地工作。

详情如下:

Local: Xampp server
htdocs/
       myapp/
             dashboard/            ---> this the website folder (Yii)
             modules/
                     v1/           -----> here are my yii2 services and controllers.

现在,当我在本地尝试 url 时:http://localhost/myapp/v1/srvc/srvdetails 工作正常。

当我尝试 Azure URL 即 http://xxxxxx.azurewebsites.net/v1/srvc/srvdetails 不工作。

有人可以帮助我吗?

根据您的描述,您的应用程序中似乎有一个 .htaccess 文件来隐藏 URL 中的 index.php 模式。由于 PHP 脚本由 Azure Web Apps 上的 IIS 处理,因此您可以尝试生成一个包含以下内容的 web.config 文件来代替您的 .htaccess:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>

<directoryBrowse enabled="false" />

  <rewrite>
    <rules>
      <rule name="Hide Yii Index" stopProcessing="true">
        <match url="." ignoreCase="false" />
        <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" 
              ignoreCase="false" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" 
              ignoreCase="false" negate="true" />
        </conditions>
        <action type="Rewrite" url="index.php" appendQueryString="true" />
      </rule> 
    </rules>
  </rewrite>
</system.webServer>
</configuration>

否则,您可以提供完整的申请结构供我们进一步诊断。如有任何疑问,请随时告诉我。