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

Leading slash missing when Slim 3 installed in subfolder #1554

Closed
tuupola opened this issue Oct 23, 2015 · 5 comments
Closed

Leading slash missing when Slim 3 installed in subfolder #1554

tuupola opened this issue Oct 23, 2015 · 5 comments
Labels

Comments

@tuupola
Copy link
Contributor

tuupola commented Oct 23, 2015

With Slim 3 both rc1 and 3.x-dev the code below returns /foo/bar when installed in document root. However when installed into subfolder it returns foo/bar without the leading slash. It does not matter whether RewriteBase is set or not.

require_once "./vendor/autoload.php";

$app = new \Slim\App;
$app->get("/foo/bar", function ($request, $response, $args) {
    return $response->write($request->getUri()->getPath() . "\n");
});

$app->run();
@tuupola tuupola changed the title Leading slash missing when Slim 3 installed in subfoder Leading slash missing when Slim 3 installed in subfolder Oct 23, 2015
@akrabat akrabat added the Slim 3 label Oct 29, 2015
@akrabat
Copy link
Member

akrabat commented Oct 29, 2015

I believe that this is intentional.

If the path is relative, (no leading /), then the rest of the path can be found in getBasePath().
If the path is absolute (leading /), then the base path is empty.

@tuupola
Copy link
Contributor Author

tuupola commented Oct 29, 2015

Ok. I thought it might be a intentional. Currently I just use workaround below to always get leading slash. Although getBasePath()seems to be the correct way to go.

$uri = "/" . $request->getUri()->getPath();
$uri = str_replace("//", "/", $uri);

@tuupola tuupola closed this as completed Oct 29, 2015
@akrabat
Copy link
Member

akrabat commented Oct 29, 2015

Really, you should use:

$uri = $request->getUri()->getBasePath() . $request->getUri()->getPath();

@silentworks
Copy link
Member

@akrabat is getBasePath not a Slim 3 specific method? I think @tuupola is trying to avoid that and have his middleware's work with any PSR7 implementation.

@akrabat
Copy link
Member

akrabat commented Oct 30, 2015

Fair enough :)

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

No branches or pull requests

3 participants