Преобразование .htaccess в Google App Engine Flex (перенаправления 301) - PullRequest
0 голосов
/ 04 сентября 2018

У нас есть сайт, который мы переносим на Google App Engine Flex Env. Большинство страниц сайта куда-то перенаправляются, но есть и такие, которые остаются доступными.

Вот наш файл htaccess в нашей системе LAMP

RewriteEngine on
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js)$
RewriteCond %{REQUEST_URI} !^/About/.*$
RewriteCond %{REQUEST_URI} !^/Services/.*$
RewriteCond %{REQUEST_URI} !^/Newsroom/.*$
RewriteCond %{REQUEST_URI} !^/Resources/.*$
RewriteCond %{REQUEST_URI} !^/Internal/.*$
RewriteCond %{REQUEST_URI} !^/Contact/.*$
RewriteCond %{REQUEST_URI} !^/Training/.*$
RewriteCond %{REQUEST_URI} !^/content/.*$
RewriteCond %{REQUEST_URI} !^/videos/.*$
RewriteCond %{REQUEST_URI} !^/app/auth/login.*$
RewriteRule (.*) https://example.com [R=301,L]
RewriteCond %{HTTP_HOST} ^site\.com$
RewriteRule ^app/auth/login$ https://another.site.com/? [R=301,L]

Возможно ли иметь эту логику в app.yaml с помощью обработчика URL-адреса (выражение reg, например, htaccess) и направлять его на жестко запрограммированный URL-адрес вместо указания на скрипт?

1 Ответ

0 голосов
/ 04 сентября 2018

ОБНОВЛЕНИЕ: Извините, ответ ниже был для 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-адреса перенаправления для каждого условия.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...