Comments (6)
Serving from a subdirectory is not supported.
From the docs:
Laravel should always be served out of the root of the "web directory" configured for your web server. You should not attempt to serve a Laravel application out of a subdirectory of the "web directory". Attempting to do so could expose sensitive files present within your application.
Reference: https://laravel.com/docs/11.x#directory-configuration
The text is the same on the 10.x docs: https://laravel.com/docs/10.x#directory-configuration
Also check for numerous past issues around the matter.
from framework.
Thanks @rodrigopedra
from framework.
Thanks @rodrigopedra for your information, but in my case there is no security issue, because only the public sub folder is reachable over the web. All other things are still outside of the public web folder. (But may I miss some thing, than it would be nice if someone can tell me, what the securety issue exactly is)
My question is still, why is there an APP_URL config variable? I can define what I want, it is always ignored.
Why does the app generates an extra subfolder in the address bar?
Why will this subfolder not used to generate the right url for the assets. Additionally I defined a prefix in the routes/web.php, but this makes it even worse. Now the url is really https://www.example.com/subfolder/subfolder/dashboard to get the dashboard and in the addressbar it is https://www.example.com/subfolder/subfolder/subfolder/dashboard but the app still tries to load all the assets on the root folder. Now the app even knows where it reaches the specific route, why it still tries to load the assets with the wrong url?
May you should think about it, to allow laravel to run in a subfolder... in my case, there is no other way... also see the discusion there:
#3918
from framework.
APP_URL
is used mainly to generate URLs when running CLI processes, like queue workers.
On HTTP requests, Laravel defers to the request's base URL.
Although I have a "contributor" label on my posts, that is for sending previous PRs. I am not a member of Laravel as an organization, nor a maintainer. So it is not up to me to decide over this.
Can't you configure a subdomain?
In the discussion you linked, Taylor says he'd accept a comprehensive PR on the matter. I guess no one could make a PR which convinced him to allow this use-case.
from framework.
Regarding your assets' base URL, you can define a custom base URL for assets using the ASSET_URL
environment variable.
Reference: https://laravel.com/docs/10.x/vite#custom-base-urls
Giving the docs a good read might answer further questions on the matter.
from framework.
I can't guarantee everything will work as expected, as this is an unsupported use-case.
But you can try adding this to your project's AppServiceProvider@boot
method:
$this->app['url']->forceRootUrl($this->app['config']->get('app.url'));
This will tell the UrlGenerator
to use the value in your .env
file's APP_URL
, as the base part of the URL.
I didn't test, and again, this is an unsupported use-case. So things may break, and third-party packages that deal with routing might handle the base URL differently.
from framework.
Related Issues (20)
- Reopening: Queue priorities & block_for shouldn't be used together HOT 5
- BelongsToMany relation withoutGlobalScope() is not being applied HOT 1
- Out of memory when sending large disk attachments HOT 5
- Str::snake doesn't handle multibyte uppercase letters HOT 1
- New error renderer is broken HOT 2
- Broadcast::auth($request); gives error in pusher HOT 1
- Optional route parameters doesn't work correctly. HOT 5
- Some events are listed and called twice since v11.9.2 HOT 3
- import.meta.env.VITE_APP_NAME and process.env.VITE_APP_NAME not working in vite.config.js HOT 1
- Difficulty Running Interactive Artisan Commands from Laravel Migrations
- Laravel 10 and Symfony 6 setDispatcher() function being provided wrong type HOT 2
- Team Update HOT 1
- The Route::dispatch method cannot pass parameters to the called controller. HOT 2
- Unexpected `value()` method behavior when querying Eloquent models. HOT 1
- Cache::forget not remove cached data with redis HOT 3
- once() usage with static methods HOT 6
- RefreshDatabaseTrait is not refreshing all database connections HOT 3
- Hoisted variable in template HOT 1
- Str::kebab Does Not Convert snake_case to kebab-case Correctly. HOT 1
- request() helper not working properly when Laravel is optimized HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from framework.