In my Laravel project, the .htaccess
in the application root redirect to /public
. The page loads and I can navigate through the webapp. But https://myproject.com/public/public/mysite
is displayed in the URL.
When I refresh the page, I get a 404 error because myproject.com/public/public/
of course doesn’t exist. When I remove the public/public
laravel redirects instantly back to https://myproject.com/public/public/mysite
.
Where does the public/public
come from? I tried some .htaccess configurations, check the .env
file, but it exist no logic reason for me why the app redirects to public/public/
.
Can anyone help me?
.htaccess in root
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
.htaccess in /public
<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]
</IfModule>
.env APP_URL
APP_URL=https://example.com
Anyone an idea? If you need more information, ask me.
Laravel 9.2
PHP 8.2.4
2
Answers
As miken32 advised:
That was completely right.
In Strato web hosting, a folder for the domain must be created in the "Webspace" menu tab. The domain must then be set to the desired root directory. I found this in the "Domains" menu tab under "Settings" (cog wheel). In my case I had to select
my-created-domainfolder/public
there.After that
php artisan route:clear
,php artisan cache:clear
andcomposer dump-autoload
and all works as aspected.You can remove .htaccess from the public directory and add this code to your root .htaccess, this will not let .env be accessible from the URL, and will resolve your current issue.