I'm trying to deploy my Symfony 4 app to Heroku and, obviously, encountering some issues with it.
I first had the "403 Forbidden" error because the document root had not been set in my Procfile.
My answer to that was, after reading other questions and answers I could find around, using any of these:
web: $(composer config bin-dir)/heroku-php-apache2 public/
web: bin/heroku-php-apache2 public/
web: vendor/bin/heroku-php-apache2 public/
web: vendor/bin/heroku-php-apache2 /public/
They all gave back different kinds of "500 Internal Server Error" pages - most of them, saying something along the lines of Request exceeded the limit of 10 internal redirects due to probable configuration error.
Which lead me to think about some issue in my public/.htaccess file instead.
With comments removed, it looks like this:
# Use the front controller as index file. It serves as a fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex app.php
# By default, Apache does not evaluate symbolic links if you did not enable this
# feature in your server configuration. Uncomment the following line if you
# install assets as symlinks or if you experience problems related to symlinks
# when compiling LESS/Sass/CoffeScript assets.
# Options FollowSymlinks
# Disabling MultiViews prevents unwanted negotiation, e.g. "/app" should not resolve
# to the front controller "/app.php" but be rewritten to "/app.php/app".
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the app.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
# Sets the HTTP_AUTHORIZATION header removed by Apache
RewriteCond %{HTTP:Authorization} .
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect to URI without front controller to prevent duplicate content
# (with and without `/app.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the start page because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
# Rewrite all other queries to the front controller.
RewriteRule ^ %{ENV:BASE}/app.php [L]
</IfModule>
<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 ^/$ /app.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
Which is indeed weird as I have no public/app.php file - however, swapping that for index.php doesn't seem to fix things either.
I really don't know what else to try, help would be much appreciated.
In my case is I did not add the route "/". Symfony load default page in local environment without that route, but in heroku we need to add it!
I show my code for your reference:
class DefaultController extends AbstractController
{
/**
* #Route("/", name="default")
*/
public function ping()
{
return $this->json([
'message' => 'pong'
]);
}
}
In case anyone else stumbles upon this trying to deploy a Symfony / Symfony 4 app, these are the steps I had to take to solve the issue:
My .htaccess file was outdated and still referenced the old Symfony 3 app.php. What I had to do was delete it and get the new one via composer require symfony/apache-pack
At this point, I still got a 500 Error and the Heroku logs weren't saying anything helpful. That's because Heroku requires you to log things to php://stderr to have them properly logged in the CLI and web interface. As such, I had to modify my config/packages/prod/monolog.yaml file to have the nested handler be like this: path: "php://stderr"
In my case, the second issue turned out being I'd forgotten to run node_modules/.bin/encore production in my postinstall script - but just redirecting logging to php://stderr should point anyone in the right direction.
Related
I tried to install .htaccess file directly from recipes as documentations says on their website(https://symfony.com/doc/current/setup/web_server_configuration.html#using-mod-php-php-cgi-with-apache-2-4), but it didn't install anything. So I went on Github of the recipe(https://github.com/symfony/recipes-contrib/blob/master/symfony/apache-pack/1.0/public/.htaccess) and copy the file into my project.
File contains:
# Use the front controller as index file. It serves as a fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex index.php
# By default, Apache does not evaluate symbolic links if you did not enable this
# feature in your server configuration. Uncomment the following line if you
# install assets as symlinks or if you experience problems related to symlinks
# when compiling LESS/Sass/CoffeScript assets.
# Options +FollowSymlinks
# Disabling MultiViews prevents unwanted negotiation, e.g. "/index" should not resolve
# to the front controller "/index.php" but be rewritten to "/index.php/index".
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the index.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$
RewriteRule .* - [E=BASE:%1]
# Sets the HTTP_AUTHORIZATION header removed by Apache
RewriteCond %{HTTP:Authorization} .+
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]
# Redirect to URI without front controller to prevent duplicate content
# (with and without `/index.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the start page because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
# Rewrite all other queries to the front controller.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>
<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 307 ^/$ /index.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
Local and remote server responds with the same error (500 Internal Server Error error was encountered).
I'm using XAMPP with Apache 2.4. I know I can install the whole project with its own web server, so locally I don't need to deal with this. Anyway, when I upload the whole project on a remote server it has the same problem as I'm having with XAMPP.
I read somewhere about changing settings in Vhost, but It doesn't solve my problem with the remote server where I can't reach configuration files for Vhost.
I don't want to sound ungrateful because Symfony is an awesome project but when I was looking for a solution to my problem I saw that this is something what people still asking since Symfony 2. I wonder why Symfony doesn't have an effective solution for this already. Or probably I'm too inexperienced.
In development mode, when i execute this command
symfony server:start -d
The application works verry well.
But when i writes the http://localhost/wafrica2/public/app_dev.php url, this error points out.
Warning: require(C:\xampp\htdocs\myproject\public/../app/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\myproject\public\app_dev.php on line 21
This is autoload.php file
It is the same error that arises when I upload to Infomaniak server after having set the file .env
this image shows the error as returned by the infomaniak server
APP_ENV=prod
DATABASE_URL=...
The .htaccess file
# Use the front controller as index file. It serves as a fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex app.php
# By default, Apache does not evaluate symbolic links if you did not enable this
# feature in your server configuration. Uncomment the following line if you
# install assets as symlinks or if you experience problems related to symlinks
# when compiling LESS/Sass/CoffeScript assets.
# Options FollowSymlinks
# Disabling MultiViews prevents unwanted negotiation, e.g. "/app" should not resolve
# to the front controller "/app.php" but be rewritten to "/app.php/app".
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the app.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
# Sets the HTTP_AUTHORIZATION header removed by apache
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect to URI without front controller to prevent duplicate content
# (with and without `/app.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the start page because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
# Rewrite all other queries to the front controller.
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
<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 ^/$ /app.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
Is it possible to run a symfony 5 application without execute the symfony server:start command? I think, the response to this question can help me.
Please, can you help me?
In Symfony >4, there is no app.php nor app_dev.php.
The environnement is defined in the .env file by the APP_ENV = prod or APP_ENV=dev for example.
If you have installed the web profiler bundle, you should have the debug toolbar while in dev. You may have to install the apache-pack bundle to make it work.
The web server root is in public folder. When you launch the server, the console should display the URL where your app is available.
Hello I'm using Symfony 3 to my new project. I have just deployed to my host. However to see my project I have to go to mysite.com/web instead of mysite.com
How can I solve this? Here goes my .htaccess file
# Use the front controller as index file. It serves as a fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex app.php
# By default, Apache does not evaluate symbolic links if you did not enable this
# feature in your server configuration. Uncomment the following line if you
# install assets as symlinks or if you experience problems related to symlinks
# when compiling LESS/Sass/CoffeScript assets.
# Options FollowSymlinks
# Disabling MultiViews prevents unwanted negotiation, e.g. "/app" should not resolve
# to the front controller "/app.php" but be rewritten to "/app.php/app".
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the app.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
# Sets the HTTP_AUTHORIZATION header removed by Apache
RewriteCond %{HTTP:Authorization} .
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect to URI without front controller to prevent duplicate content
# (with and without `/app.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the start page because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
# Rewrite all other queries to the front controller.
RewriteRule ^ %{ENV:BASE}/app.php [L]
</IfModule>
<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 ^/$ /app.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
I pointed my domain to public_html/web instead of public_html through cpanel
I am trying to update a legacy web application, so I'm trying to set up both the legacy application and the updated version in parallel, and gradually migrate to the new one.
The old application is located directly under public_html, and have put the new Application under public_html/symsale, now I want all requests directed to the new application to be rewritten and a web subdirectory added after symsale, i.e: a url like /symsale/path, must be rewritten to /symsale/web/path. for that I've create a .htaccess file and put it under the symsale directory. The contents follow:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)(symsale)(.*)$ $1$2/web$3 [L] # i've tried it both with and without the 'L'
</IfModule>
When I try to navigate to /symsale/ I get the following error
You don't have permission to access /symsale/ on this server.
However when I use /symsale/web instead, it works just fine. What's the problem here?
Note: I have seen these other questions: Apache rewrite rule to redirect all request to subdirectory containing another .htaccess and rewrite rules, Apache RewriteRule to subdirectory, .htaccess rewrite to redirect root URL to subdirectory
Note: I'm using the symfony framework (php) so there is another .htaccess file inside the web folder, which rewrites all routes to the front controller. The contents of that .htaccess follow.
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the app.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
# Sets the HTTP_AUTHORIZATION header removed by apache
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect to URI without front controller to prevent duplicate content
# (with and without `/app.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the start page because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
# Rewrite all other queries to the front controller.
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
<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 ^/$ /app.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
Here is one longshot -- mod_rewrite has an unfortunate/quirky behavior where it guesses whether you're substituting a filesystem path or a URL path. It guesses by looking at the first component of the substitution and seeing if it exists as a directory on disk (absolute path)
Do you happen to have a /symsale/ at the root of your filesystem? I believe [PT] will short-circuit this guessing and force the result to be treated as a URI.
I've created new project in symfony and I get an error prompt on each site:
An error occurred while loading the web debug toolbar (404: Not Found).
Do you want to open the profiler?
When I open the profiler there is a message
Token not found
Token "59942c" was not found in the database.
Moreover, in the cache directory the profiler directory is empty! I checked permissions and they're proper. I tried cache:clear and removing cache manually, but that didn't help.
It's often problem with event subscriber/listener.
Try run
console debug:event
And check for errors
This usually happens if the cache directory is not properly set up to allow the web servers' user to write data into them.
Under Linux, I would usually use this for development:
php app/console --env=dev cache:clear
php app/console --env=dev cache:warmup
chmod -R a+rwX app/cache/
setfacl -Rm g:www-data:rwX app/cache/
setfacl -Rm g:dev-user:rwX app/cache/
This ensures all required directories will be created and then assigned the required permissions. If you do not have ACL enabled, skip the setfacl commands.
OFC, replace www-data with your web servers' username, and dev-user with your username.
I had the same issue, it was caused because was using Apache without an .htaccess file.
If you are using Apache locally or on your server you can install Apache Pack to automatically generate an .htaccess file:
composer require symfony/apache-pack
This pack installs a .htaccess file in the public/ directory that contains the rewrite rules needed to serve the Symfony application.
https://symfony.com/doc/current/setup/web_server_configuration.html
This is a known bug in the profiler. Since Symfony 2.4, the profiler persisting the data used by the WDT is the very last thing done by Symfony.
The alert you see means that the profiler has not been able to find the token requested in the 2500ms allowed, However if you click OK in the alert, you should be redirected to the profiler and figure out what precisely is slow.
Sometimes, on big projects (custom Sylius app in my case), profiler data generates very slowly.
Symfony checks things only 5 times each 1000 ms, so if data was not generated during 5 seconds - you will get An error occurred while loading the web debug toolbar.
To understand whether this is a case - open _wdt url at new tab - if it 404, but after some time - 10-15-30 seconds it become 200 - then this is a case.
To fix this, you should override vendor/symfony/web-profiler-bundle/Resources/views/Profiler/base_js.html.twig (to templates/bundles/WebProfilerBundle/Profiler/base_js.html.twig) and replace { maxTries: 5 } to { maxTries: 30 }.
After that, script will be trying to get profiler / web debug toolbar page for 30 seconds which hopefully will be enough for your app to generate profiler data:
I had the same issue after upgrading Symfony 2.3->2.6. After upgrading web/app_dev.php it fixed the issue. I believe you need the Debug::enable(); line.
Need .htaccess file for Apache. I am not sure, why there is no default in Symfony like Laravel. This one if copy from Laravel and help with this problem, too.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Had the same issue after upgrading 2.6 -> 2.8 on a 2.4 era project. Got a useMicrosecondTimestamps error with the node layer. Fixed by nuking rm -r app/cache/*. #marenkay's method did not clear the node-php server cache.
Try to edit or add your htacces file like this
# Use the front controller as index file. It serves as a fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex index.php
# By default, Apache does not evaluate symbolic links if you did not enable this
# feature in your server configuration. Uncomment the following line if you
# install assets as symlinks or if you experience problems related to symlinks
# when compiling LESS/Sass/CoffeScript assets.
# Options FollowSymlinks
# Disabling MultiViews prevents unwanted negotiation, e.g. "/index" should not
resolve
# to the front controller "/index.php" but be rewritten to "/index.php/index".
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the index.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
# Sets the HTTP_AUTHORIZATION header removed by Apache
RewriteCond %{HTTP:Authorization} .
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect to URI without front controller to prevent duplicate content
# (with and without `/index.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the start page because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
# Rewrite all other queries to the front controller.
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>
<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 307 ^/$ /index.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
If you do not get 404 every time, but periodically and use docker at the same time, then you should check that you do not have conflicts with the containers accepting requests. In my case, several projects were launched with the same name "fpm" and, of course, only one of them had a real token