php - 让 PHP 路由库与 Azure 应用服务一起使用?
问题描述
我有一个使用 Steampixel\Route 进行路由的 PHP 应用程序。我无法让它与 azure 一起使用。我创建了另一个 azure 应用服务,看看我是否可以让 Steampixel\Route 或另一个路由库工作。假设我的 index.php 如下:
require_once __DIR__ . '/vendor/autoload.php';
use Steampixel\Route;
Route::add('/testroute', 'onTestRoute');
Route::add('/', 'onIndex');
Route::run('/');
function onIndex() {
echo 'on index route<br/>';
echo 'go to <a href="/testroute">testRoute</a> to see if routing works';
}
function onTestRoute() {
echo 'on test route';
}
在本地运行时,一切正常。但是部署到天蓝色,/testroute 给我一个 404 not found 错误。我在项目根目录中添加了一个 web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="redirect all requests" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
还有一个.htaccess:
DirectoryIndex index.php
# enable apache rewrite engine
RewriteEngine on
RewriteBase /
# Deliver the folder or file directly if it exists on the server
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Push every request to index.php
RewriteRule ^(.*)$ index.php [QSA]
依然没有。当部署在 azure 上时,这个基本应用程序仍然无法将我重定向到 /testroute。有谁知道如何让它工作?提前致谢。
解决方案
推荐阅读
- django - 在 django 模板中为“用户”提供了什么
- android - 在 Android 应用程序中检查 Internet 连接
- android - Android Studio?工具栏错误
- python - 想要使用 lambda 函数来更改单元格的类型(如果它是 float 类型)
- c++ - C++:将多态 lambda 传递给函数
- vb.net - System.net.web 异常。远程服务器返回错误:(530)未登录
- javascript - map函数里面的具体map函数
- php - Symfony Doctrine:向现有阅读器添加新的新注释命名空间
- javascript - 隐藏和显示带有点击事件的 div
- python - 用python中的Pattern中的另一个数字替换一个数字