Closed piotr-cz closed 7 years ago
You should be setting your webroot to the public folder, not using an .htaccess to redirect queries.
+1 on geggleto. public is called public, because it should contain all files exposed to public, as its the projects document root.
I know. The point is how the base path resolution works now.
Image I'm using (invisible) server redirect to redirect http://foo.org/oldsite
to http://foo.org/newsite
on the server. The resolution mechanism assumes that request uri overlays physical path which is not correct.
So the user will see http://foo.org/oldsite
in browser, $basePath
will be set to ''
and $virtualPath
to newsite
Arguably, one solution is to add middleware that does:
$request = $request->withBasePath('/newsite')->withPath('');
@akrabat Yes, but if I'd like to use any routes in application I'd have to resolve the $virtualPath
in middleware.
I don't understand. That line would work the same way as using a config setting.
Yes for no routes, but not for http://foo.org/oldsite/about
Hmm... the point of setting it into BasePath
was so that routes would work. I'll have to test it now!
I have no idea what to actually do with this issue. What specific change do you propose should be made?
This is such a huge edge case, I am for not doing anything.
I would ignore this one. On Sun, Nov 29, 2015 at 9:23 AM Glenn Eggleton notifications@github.com wrote:
This is such a huge edge case, I am for not doing anything.
— Reply to this email directly or view it on GitHub https://github.com/slimphp/Slim/issues/1571#issuecomment-160419050.
@akrabat I'd like to see is that the method would respect project uri set manually in the container settings.
But I don't mind closing the issue ATM either
How about PR'ing what you imagine?
I'll prepare PR, but it may take some time until I get some time
Quite old, closing :)
Let's assume that the document root is set to
./
, public folder resides in./public
(just like in slim3-skeleton app) and the.htaccess
in the document root redirects all requests to public folder using [L] flag:In this scenario base path resolution in
Uri::createFromEnvironment
doesn't work properly: real base path value instead of being stored in$basePath
variable is stored in the$virtualPath
.I admit that this is very sketchy example and I use it only during local development when I'm too lazy to setup separate virutal host for each project.
The point is that using
$_SERVER['SCRIPT_NAME']
and$_SERVER['REQUEST_URI']
for$basePath
and$virtualPath
resolutions will fail when using complex server rewrites.One solution may be to provide public folder path as an environment variable (as I've done in the example), but more bullet-proof solution I'd like to see is that the method would respect project uri set manually in the container settings.
This could help solving another issue: the connection could be set manually as being secure or not as this is not trivial to autodetect when behind load balancer.