-1

I have a Slim 4 app running and set some recurring url param as a base path to not show this in url generation.

Request flows:

  1. Call to http:demo.xyz?p1=a ---> rewrite to http://slim.app/url/demo.xyz?p1=a through a Varnish proxy
  2. Call to http://slim.app/url/demo.xyz?p1=a directly

Both calls need to work.

Inside a middleware I set /url/demo.xyz as base path so the URLs generated are http://demo.xyz?p1=a.

The problems with this are:

  • The base path is not recognized by routes.php as something to pass params, so url/abc is not matched.
  • I still need to have the value of the url param to fetch some things inside the Slim app.
  • My routes need to match this structure to work with both request flows.
 $app->group('/url/{url}', function (RouteCollectorProxy $group) {
    $group->get('[/[/city/{city}]]', IndexAction::class)->setName('home');
    //...
});

Any idea to get this to work?

This is connected to the question placed here.

codedge
  • 4,754
  • 2
  • 22
  • 38

1 Answers1

0

In the middleware, you can use Request::getUri() method to get entire uri. Then, if matches with first url format "http:demo.xyz?p1=a" do:

return $response
  ->withHeader('Location', 'https://www.example.com')
  ->withStatus(302);

if matches to "http://slim.app/url/demo.xyz?p1=a" do needed stuff to proceed.

Enrique René
  • 510
  • 1
  • 5
  • 19