Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Router $basePath is always null #2541

Closed
BoGnY opened this issue Nov 19, 2018 · 1 comment
Closed

Router $basePath is always null #2541

BoGnY opened this issue Nov 19, 2018 · 1 comment

Comments

@BoGnY
Copy link

BoGnY commented Nov 19, 2018

I've a similar problem of #2107 and #1964 on Slim 3.11..
$basePath is always null, so every time I use path_for() on my twig template file, Slim redirect site to https:///login instead https://MY_WEBSITE/login.....

To solve this, I've momentainly merged #2519 to understand if is really always null, after that, I fix it with this middleware:

$container = $app->getContainer();

$app->add(function (Request $request, Response $response, $next) use ($container) {
    $container->debugbar->addMessage('FIRST BASEPATH SET: '.$container->router->getBasePath()); //This return an empty string
    if (null === $container->router->getBasePath() || '' === $container->router->getBasePath()) {
        $container->router->setBasePath(getenv('APP_URL'));
    }
    $container->debugbar->addMessage('AFTER BASEPATH SET: '.$container->router->getBasePath()); //This return the correct base path

    return $next($request, $response);
});

But the main problem is that, the same code, on different platform, return two different result...
Same php version, same apache version, same extension enabled, same php.ini and same httpd.conf...

On my localhost wamp Slim works without middleware fix ($basePath is set correctly), but on my ubuntu test vps, the middleware fix is mandatory ($basePath is always null)...

Because it is a 2 years old bug, any idea how to fix it??

@l0gicgate
Copy link
Member

I think this has to do with the .htaccess in your setup with Apache. This problem isn't encountered with Nginx.

See issue #2512 for further information about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants