I am developing project using laravel
and I have directory named ‘profile’ in public folder.
also I have route named /profile also
Route::get('/profile', [UserController::class ,'showProfile']);
when I visit ‘localhost/profile’ url, it goes to public/profile folder
I have 2 ubuntu server.
this project works well on one server, but not working on other one.
please help me…
3
Answers
What are the intentions of using the public profile folder for?
Maybe is there something you need to change in the
.htaccess
in the public folder. And maybe consider renaming yourpublic/profile
folder to another name.Maybe first try to rename the folder to make sure that everything works as expected.
The problem is that the web server initially tries to open a directory or file at the specified URL with that name. And if the file or directory is not found, it passes the address processing to the Laravel application.
You can override this behavior by hardcoding the
/profile
URL to be handled only by the Laravel application.Example Apache 2 configuration so that Laravel processes all URLs starting with
/profile
(/profile/styles.css
,/profile/script.js
, etc.):An example Apache2 configuration so that Laravel only processes the URL
/profile
, and/profile/**
would display the contents of files or directories:The general convention for utilising the public directory would be to create some subdirectory, generally
assets
in order to use the assets helper, and populate this deeper.This is exactly what asset bundlers like vite will do and helps keep that initial namespace clean.
If you are using this to directly store images for a users profile, for instance, using a publicly accessible storage disk may be a more effective way of managing this content