简体   繁体   English

如何更改laravel 5.2中的URL默认值?

[英]how can i change the URL default in laravel 5.2?

How can I change the url('/') default value in Laravel 5.2? 如何在Laravel 5.2中更改url('/')默认值?

I tried changing it on config/app.php and .env but still doesnt work. 我尝试在config / app.php和.env上更改它,但仍然无法正常工作。

// 'url' => env('APP_URL', 'http://localhost'),
'url' => 'http://localhost',

Here is a snippet from the app.php : 这是来自app.php的片段:

/*
    |--------------------------------------------------------------------------
    | Application URL
    |--------------------------------------------------------------------------
    |
    | This URL is used by the console to properly generate URLs when using
    | the Artisan command line tool. You should set this to the root of
    | your application so that it is used when running Artisan tasks.
    |
    */

    'url' => env('APP_URL', 'http://localhost'),

This tells that this url is only used for the local artisan task. 这表明此url仅用于本地工匠任务。

But you are trying to redirect your home route to something like mrvince , which clearly states that you will be changing the url when a user arrives to your home route. 但是,您正在尝试将自己的home route重定向到mrvince类的mrvince ,该名称明确指出,当用户到达您的家庭路线时,您将更改网址。

Your purpose to change the url is different ie you always might want to change the home route to something other but if you get succeed on changing the url, it will not work for production purpose as you will not use Artisan server in production . 更改url目的是不同的,即,您始终可能希望将家庭路由更改为其他路由,但是如果成功更改URL,则它将无法用于生产目的,因为您将不会在production使用Artisan server

So, i prefer to redirect the request to some other place if needed like: 因此,如果需要,我更喜欢将请求重定向到其他地方:

Route::get('/', function () {
    return redirect()->route('profile');
});

Route::get('profile', [
    'as' => 'profile',
    'uses' => 'SomeController@someMethod'
]);

Also have a look at this docs: 也看看这个文档:

https://laravel.com/docs/5.3/routing#named-routes https://laravel.com/docs/5.3/routing#named-routes

Hope this helps. 希望这可以帮助。 If i am not correct could anyone correct me in this scenario. 如果我不正确,在这种情况下任何人都可以纠正我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM