- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个问题,我在这个网站上看到过很多讨论,但我还没有看到它针对运行 php72 或 php73 运行时的应用程序进行了讨论(即使有,我也没有看到它得到解决).
我正在尝试获得最直接的 php Web 服务器的基本功能,即当您导航到一个目录时,它可以为位于该目录中的 index.php 提供服务。
显然开箱即用,Google App Engine 不会这样做,但我必须相信有一种方法可以获得该功能。
我看了这个问题,看起来它有我需要的东西:
Google app engine redirect everything to index.php
问题是,如果您在 php72 或 php73 运行时中,那将不起作用,而我需要这样做。 app.yaml 文件中 script
名称的唯一可接受值是 auto
。大多数所有其他问题都有相同类型的答案(因为它们告诉您重新定义脚本值,但在我的运行时中这不起作用)。
这是我当前的代码...我正在正确地提供我所有的图像、js 和 css:
runtime: php73
handlers:
- url: /assets
static_dir: assets
# Serve static files as static resources.
- url: /(.+\.(gif|png|jpg|svg|webp|jpeg|js))$
static_files: \1
upload: .+\.(gif|png|jpg|svg|webp|jpeg|js)$
- url: /style
static_dir: style
- url: /js
static_dir: js
- url: /.*
script: auto
这是我的目录结构:
根目录下的 index.php 完美地服务于一切,当我尝试导航到 /forgot/
或 /setup-account/
目录时不起作用。当我说不起作用时,我的意思是根 index.php 提供的内容与 /forgot/
或 /setup-account/
中显示的内容相同> 目录。
如何从 /forgot/
和 /setup-account/
目录提供 index.php 文件?
最佳答案
因此,我将尝试尽可能深入地回答这个问题,因为这是我一直在寻找的,但我在其他任何地方都找不到。
FIRST - 这是使用 php72 或 php73 运行时,在该运行时之前的任何内容在 SO 和其他站点上都有其他答案,以及在这两个运行时之后的任何内容,我只是不确定。
此外,让我们定义我的问题:
我的问题是,当我导航到我的 PHP Web 应用程序中的子文件夹时(我的 index.php 文件包含我的 Controller 代码),唯一会弹出的是我应用程序根目录下的内容(以前称为“/”)。因此,当我导航到“/”时,一切都在正确呈现和显示,但无论何时我离开那里,它都会继续显示相同的内容。
我过去(现在仍然)对 Laravel、Slim 或 Symfony 这样的框架不感兴趣,所以我必须弄清楚如何在没有框架的情况下做到这一点,这被证明具有挑战性,因为它看起来像所有在线教程只处理框架。所以,下面是我的普通 PHP,不到 20 行代码回答了如何做到这一点。
1. 在您的 app.yaml 中,将入口点路径添加到将成为您的“路由器”的脚本。我的看起来像这样(查看评论以获得简要解释):
runtime: php73
# I'm choosing to serve my router from the root of my application, and call it router.php.
# You can serve it from wherever, and call it whatever.
# So, for instance, you this line could read: serve /model/folder/path/whatever.php
entrypoint: serve /router.php
handlers:
# my handlers for css, js, and images
2. 现在,在我的 router.php
中,这是让奇迹发生的代码:
<?php
require_once get_required_php_file(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
function get_required_php_file(string $path): string {
// just require the index file
if ($path === '/') {
return 'index.php';
}
// getting the last character to strip it off if it's a "/"
$last_char = \substr($path, -1);
$pathname = ($last_char === '/' ? rtrim($path, '/') : $path);
// stripping the leading "/" to get the true path
$pathname = ltrim($pathname, '/');
// setting the full require path
$full_php_path = $pathname.'/index.php';
// returning the path as long as it exists, if it doesn't, return 404.php
return (\file_exists($full_php_path) ? $full_php_path : '404.php');
}
请查看评论以了解此处发生的情况……尽管它应该是不言自明的。我从用户那里获取 request_uri 并将 index.php 附加到路径名上并要求它。
所以,就是这样。 12 行代码的廉价普通路由器(如果您消除空格和注释)。
陷阱1. 如果像我一样,您的 View 文件包含这样的页眉和/或页脚:
// view.php
<?php
declare(strict_types=1);
include_once '../view/header.php';
include_once '../view/footer.php';
您需要遍历并更改您的包含路径以从您的路由器文件所在的位置包含。对于我的示例,这很简单,因为我将路由器放在根目录下。所以如果我想更新上面不正确的 View 示例以正确包含文件,上面的代码现在看起来像这样:
// view.php
<?php
declare(strict_types=1);
include_once 'view/header.php';
include_once 'view/footer.php';
关于php - 默认路由到/directory/index.php Google App Engine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57206392/
当我尝试构建我的项目时,我遇到了这样的错误: FAILURE: Build failed with an exception. * What went wrong: Execution failed
我正在尝试从 Here 构建适用于 linux 3.7 内核的 Mali 驱动程序. 有一个单独的构建脚本,例如, #!/bin/bash export KDIR=/path/to/kernel/di
有没有一种方法可以使用普通的 lisp 创建目录。我想先创建一个文件夹,然后将我的 .txt .png 文件放入其中。我知道首先我可以在外部创建文件夹,然后使用 with-open-file 等在目录
Visual Studio 提示每次编译警告 MSB8029:中间目录或输出目录不能位于临时目录下,因为它可能导致增量构建出现问题。 我正在检查项目并更改了输出目录和中间目录,但我仍然在我的解决方案中
Visual Studio 提示每次编译警告 MSB8029:中间目录或输出目录不能位于临时目录下,因为它可能导致增量构建出现问题。 我正在检查项目并更改了输出目录和中间目录,但我仍然在我的解决方案中
我的客户安装了 Keycloak 以从 AWS Cognito 代理用户。 我需要这个 Keycloak 来代理来自 Azure Active Directory 的用户。 客户拥有 AAD 的 OF
我想从 macOS 上 parallel 命令的所有潜力中受益(似乎存在 2 个版本,GNU 和 Ole Tange 的版本,但我不确定)。 使用以下命令: parallel -j8 find {}
我需要实现一个 Active Directory(本地)管理器,用户可以在其中执行所有任务,例如添加用户、删除用户、分配许可证和分配组等。用户有用户名、密码和域 Controller 名称,所以他只需
我正在编写一个使用PHP adLDAP库与Active Directory交互的应用程序。 为了测试该应用程序,我需要使用Active Directory架构的本地LDAP DB以及示例数据。 我已经
我有一个包含两个域 AA.RR.COM 和 BB.RR.COM 的 Active Directory 林,其中包含用户和组。我需要搜索两个域中的用户,同时查询其中一个域(例如 AA.RT.COM)如何
我使用 Proxy-Address 属性作为确定用户电子邮件地址的主要方法(我只关心以“SMTP:”或“smtp:”为前缀的地址,此外,我使用以大写字母为前缀的地址SMTP 来确定主地址 - 这不是
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
所以我有一个目录 - 让我们说/dir/。在里面我有这些文件夹-/目录/fold1//目录/fold2//dir/fold3/ 这些文件夹 (fold1,2,3) 中的每一个都可能包含一个名为 foo
我正在使用 PHPmotion 在我本地的 ubuntu 机器上。 优步上传者在 phpmotion 中用于将文件上传到服务器。这是使用 perl 脚本(位于“ www/cgi-bin ”)上传文件。
我正在为我的公司开发一个基于 Web 的 Intranet。我只想知道用户使用事件目录登录详细信息登录应用程序是一件好事,还是我应该与应用程序数据库一起创建登录名。如果有什么比这更好的,请提出建议。这
我们有带有 AD 模块 1.0.4 的 Sitecore 6.5。 DEPARTMENT\SitecoreUsers AD 组中的用户可以登录 Sitecore,但 DEPARTMENT\Siteco
我使用的 AD 设置具有存储为(多个)安全组成员的用户。 我正在使用读取用户的 memberof 属性的软件来计算访问权限。 在 AD Explorer 中,我可以看到用户的 memberof 属性显
我们有一个在 .NET 上编写的 SaaS 应用程序,我们需要为我们的客户提供各种 SSO 方法。 不久前,我们对 OpenID 进行了标准化,希望这会成为一个通用标准,让我们不必支持不同的标准。不幸
我有 .Net 代码可以读取/写入我们本地的 Active Directory 域。阅读部分已经过测试并且工作正常,但我想测试“写作”部分。我的应用程序将修改事件目录中的一些用户配置文件,但我不想在实
我正在运行一个 ASP.NET 4.0 应用程序,它使用用户名(即 HttpContext.Current.Request.LogonUserIdentity.Name.ToString())来管理对
我是一名优秀的程序员,十分优秀!