ОБНОВЛЕНИЕ: Извините, ответ ниже был для App Engine Standard. Я пропустил Flex
часть. Вот как это сделать в Flex Env
:
См. Примеры по адресу: https://github.com/GoogleCloudPlatform/getting-started-php
app.yaml :
runtime: php
env: flex
runtime_config:
document_root: web
/ веб / index.php
<?php
require_once __DIR__ . '/../vendor/autoload.php';
$app = new Silex\Application();
$app->get('/app/auth/login{somestr}', function($somestr) {
header('Location: https://www.someothersite.com/somewhere{$somestr}');
exit();
});
$app->get('/', function() {
return 'Hello World';
});
$app->get('/{oldDir}/{oldPath}', function($oldDir, $oldPath) {
switch ($oldDir) {
case "About":
header('Location: https://www.someothersite.com/{$oldDir}/{$oldPath}');
exit();
break;
case "videos":
header('Location: https://www.someothersite.com/new_videos/{$oldPath}');
exit();
break;
.....
default:
handle other urls
}
})
/*
Depending on how many other paths there are, you may want to use
separate handlers for each (About, Services, etc.) instead of the
switch function, like:
*/
$app->get('/About/{oldPath}', function($oldPath) {
header('Location: https://www.someothersite.com/NewAbout/{$oldPath}');
exit();
})
?>
Для App Engine Standard Env :
Нет, но да. app.yaml
все равно должен указывать на скрипт, но этот скрипт может выполнять перенаправление:
handlers:
- url: /.*\.(gif|jpe?g|png|css|js)$
script: redirect.php
- url: /(About|Services|Newsroom|...videos)/.*$
script: redirect.php
- url: /app/auth/login.*
script: redirect.php
Затем ваш скрипт redirect.php
выполняет перенаправление:
<?php
header('Location: https://www.someothersite.com' + $_SERVER['REQUEST_URI']);
exit();
?>
Вы можете выполнить некоторое сопоставление регулярных выражений или логику if / then, чтобы увидеть, предназначен ли URL для изображения и т. Д., И установить различные URL-адреса перенаправления для каждого условия.