I am attempting to install my Laravel 10 project in a subfolder so that I can access it at example.com/laravel-project/
instead of example.com/laravel-project/public/
. Here is the .htaccess configuration I tried in the /laravel-project/
directory:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/ [L]
</IfModule>
This configuration results in a Laravel-styled 404 error when accessing the subfolder URL. I’ve reviewed other questions and it seems that something has changed in Laravel 10 that prevents this setup from working as it did in previous versions. I’d like to avoid using php artisan serve
. Additionally, I have the following set in my .env file, which should also be correct:
#...
APP_DIR=laravel-project
APP_URL=http://example.com/laravel-project
#...
How can I configure the .htaccess file or Laravel 10 setup to correctly render the homepage at the subfolder URL without having to go to public/
in the URL?
Edit: The site will be on shared hosting
2
Answers
I managed to solve the issue. The
.htaccess
file withRewriteRule ^(.*)$ public/ [L]
was correct. Here's the additional configuration I made:I added a new environment variable for the asset URL:
I updated the RouteServiceProvider (
app/Providers/RouteServiceProvider.php
) to prefix the routes with the subdirectory name:I would do it at the Web Server level using Virtual Host Aliases as you seem to be using Apache.
Untested:
That should enable you to navigate to
example.com/laravel-project
and see your public folder.