'Add .htaccess file outside the Laravel public

please I added a .htaccess file outside the public folder in the Laravel 9 project without copying or removing all files from the public to the project folder. Code for the .htaccess is below:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ ^$1 [N]

    RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
    RewriteRule ^(.*)$ public/$1

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ server.php
    RewriteRule ^.env - [F,L,NC]

</IfModule>

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php73” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php73 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

the .htaccess worked okay on Laravel 7 and 8 instead of Laravel 9. What do I miss?



Solution 1:[1]

The line

    RewriteRule ^ server.php

is likely causing the issue if that file doesn't exist - that file was deleted in Laravel 9 and moved within the framework. Adding it back (e.g. if you had customizations) shouldn't cause any issues, or (not tested) you can try updating it to public/index.php as suggested in the comment below.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1