I deployed a laravel/inertia/vue project on apache in a subdirectory of /var/www/html – let’s call it “myapp”.
On the browser: http://localhost/myapp shows as http://localhost/myapp/myapp, repeating myapp.
The Virtual host settings on 000-default.conf are as follows:
… Original settings
#Settings for myapp
Alias /myapp /var/www/html/myapp/public
<Directory /var/www/html/myapp>
AllowOverride All
Options -Indexes
</Directory>
The .htaccess on myapp/public is the original with the following line added:
RewriteBase /myapp/
Everything works fine in myapp except, for example when showing an item
http://localhost/myapp/myapp/users/3 and press refresh on the browser, I get 404 not found because the working is is actually http://localhost/myapp/users/3 without the repeated myapp.
Is there a way to setup the deployment so it does not repeat myapp and when I type
http://localhost/myapp it actually is http://localhost/myapp,
I have tried several suggestion by googling the problem stated but I have not been able to find a solution
2
Answers
It seems like the configuration needs a small adjustment to resolve this behavior.
To address the repeated subdirectory issue, please follow these steps:
Inside the public directory of your Laravel application (myapp/public), ensure that the .htaccess file contains the following line:
This step is already mentioned in your description, but just make sure it’s correctly implemented.
After making these changes, clear your Laravel configuration cache using the following command:
Restart Apache to apply the changes to your virtual host configuration:
Reference:
https://lucabecchetti.medium.com/configure-laravel-to-work-in-a-subdirectory-and-with-artisan-serve-at-the-same-time-654ba0c1fd0b
The inertia-laravel has a bug which makes a route (eg. http://localhost/my-project) change to (eg. http://localhost/my-project/my-project)
If you are using inertia in your project and having repeated sub-directory issue, this could be the reason.
The issue has been resolved in latest version. Issue link
Update
inertiajs/inertia-laravel
to resolve.Or
You want to fix manually, do the following steps.