如何解决通过入口点标准使用前端控制器进行php72动态网址路由不起作用,Google App Engine [GAE]
我在GAE的网站上没有读取我的动态URL,因为我想使用传入的GET查询我的数据库。
就目前而言,Php72不允许从app.yaml进行路由,该路由必须来自前端控制器的入口点,入口点的默认值为publichtml / index.php或index.php。
我将我的名称更改为worker.php。下面的listing.php URL是动态的,我的意思是listing / random-dynamic-text-here,而index.php和about.php是静态页面。
注意:页面index.php以及about.php和listing.php被调用并显示在浏览器中,但是我无法获取$ _GET [“ linkcheck”]的内容;在listing.php中。请参阅下面的内容。
app.yaml
runtime: php72
runtime_config:
document_root:
handlers:
- url: /.*
script: auto
secure: always
redirect_http_response_code: 301
entrypoint:
serve worker.php
//进入点worker.php
<?php
ini_set('allow_url_fopen',1);
switch (@parse_url($_SERVER['REQUEST_URI'])['path']){
case '/':
require 'index.php';
break;
case '/index':
require 'index.php';
break;
case '/index.php':
require 'index.php';
break;
case '/about':
require 'about.php';
break;
case '/about.php':
require 'about.php';
break;
case '/listing':
require 'listing.php';
break;
case '/listing.php':
require 'listing.php';
break;
case '/listing/':
require 'listing.php/';
break;
case '/listing.php/':
require 'listing.php/';
break;
default:
http_response_code(404);
header("Location: https://www.example.com/404");
exit();
}
?>
index.php
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>Home</h1>
</body>
</html>
about.php
<html>
<head>
<title>About</title>
</head>
<body>
<h1>About</h1>
</body>
</html>
下面的listing.php是我期望$ _GET [“ linkcheck”];的文件/页面;
listing.php
<html>
<head>
<title>Listing</title>
</head>
<body>
<h1><?php $cool = $_GET["linkcheck"]; echo $cool; ?></h1>
</body>
</html>
解决方法
要实现此目的,您需要修改两个文件:
worker.php
<?php
ini_set('allow_url_fopen',1);
$path = @parse_url($_SERVER['REQUEST_URI'])['path'];
switch ($path){
case '/':
require 'index.php';
break;
case '/index':
require 'index.php';
break;
case '/index.php':
require 'index.php';
break;
case '/about':
require 'about.php';
break;
case '/about.php':
require 'about.php';
break;
case '/listing':
require 'listing.php';
break;
case '/listing.php':
require 'listing.php';
break;
case '/listing/':
require 'listing.php';
break;
case (preg_match('/listing.*/',$path) ? true : false) :
require 'listing.php';
break;
default:
http_response_code(404);
header("Location: https://www.example.com/404");
exit();
}
?>
这里的区别是匹配以/listing
开头的正则表达式,并将其发送到列表脚本。
第二项修改是在列表中添加以下行:
<h1><?php $cool = $_GET["linkcheck"]; echo $cool; ?></h1>
被这个代替:
<h1><?php $cool = $_SERVER['REQUEST_URI']; echo $cool; ?></h1>
我测试了它,现在可以正常使用了。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。