Closed tsarma closed 4 years ago
What does the image request look like? Is it even handled by your webserver?
Request looks like:
GET http://localhost:3002/assets/images/2/test-image-757ba688.jpg 404 (Not Found)
So does your server rewrite everything to index.php
? It should :)
Yes, when I click the detail of image is shows up, but not in list view.
That will load the original filename. Your webserver configuration is incorrect.
You have to configure the webserver so that it serves real files when they exist and rewrites everything else to index.php
. Otherwise things are not going to work.
I'm not sure you can do this with the built-in webserver out of the box. Maybe you need to write a router file. Anyway, it's not a Contao issue.
Technically Contao still kind of supports not rewriting everything to app.php
/index.php
, since this line is included in the default .htaccess
for example:
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
# When mod_rewrite is not available, we instruct a temporary redirect of
# the start page to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 302 ^/$ /index.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
The internal php webserver does not support .htaccess
, as it is an apache config file.
But you could use a router file (as mentioned by @Toflar):
php -S localhost:8080 router.php
<?php
// router.php
declare(strict_types=1);
chdir(__DIR__);
$filePath = realpath(ltrim($_SERVER['REQUEST_URI'], '/'));
if ($filePath && is_dir($filePath)) {
// attempt to find an index file
foreach (['index.php', 'index.html'] as $indexFile) {
if ($filePath = realpath($filePath . DIRECTORY_SEPARATOR . $indexFile)) {
break;
}
}
}
if ($filePath && is_file($filePath)) {
// 1. check that file is not outside of this directory for security
// 2. check for circular reference to router.php
// 3. don't serve dotfiles
if (0 === strpos($filePath, __DIR__ . DIRECTORY_SEPARATOR) &&
$filePath !== __DIR__ . DIRECTORY_SEPARATOR . 'router.php' &&
'.' !== substr(basename($filePath), 0, 1)
) {
if ('.php' === strtolower(substr($filePath, -4))) {
// php file; serve through interpreter
include $filePath;
} else {
// asset file; serve from filesystem
return false;
}
} else {
// disallowed file
header('HTTP/1.1 404 Not Found');
echo '404 Not Found';
}
} else {
// rewrite to our index file
include __DIR__ . DIRECTORY_SEPARATOR . 'index.php';
}
@Toflar Thank you for the explanations. @bytehead I tried your router. I helped generate the thumbnail but it breaks the rest, no css, no js is loaded.
Anyway, it's not a Contao issue.
I do think we should remove the fallback in the default .htaccess for Contao 4.8+
In my case, as I am developing on native php webserver .htaccess is not relevant.
I think now Contao imposes one more configuration requirement. It was so much fun to have Contao running without needing to pull up Apache webserver, but sadly no more.
Just use the symfony cli and it works even better.
The PHP built-in webserver is not meant to be used to run a CMS anyway. It's useful for some quick hacks and to run tests on CI etc. Also Apache is not a requirement at all. Contao just needs the ability of the server to deliver a real file if it exists and fall back to the general entrypoint which is one of the most basic requirements of any webserver.
In my case, as I am developing on native php webserver .htaccess is not relevant.
I know, I am just saying in general, that you cannot use Contao without a rewrite to PHP any more - and thus any reference to that should be removed.
Up until now, all my Contao 4 projects are build on php built-in web server, even when it is not meant to run CMS. So I was expecting it should also work for Contao 4.8.
@bytehead Thanks for the Tip: It works great.
Affected version(s) Contao 4.8.2
Description
When I run Contao on php internal webserver (
php -S localhost:3000
normally I do it during development), I don't see thumbnails in backend file manager.How to reproduce
Run your installation on php internal webserver
https://filebin.net/z4bg93pvxro9hfzj/File-Manager.mp4?t=ws7sj538