【问题标题】:How to changed default path '/public' name in Laravel如何在 Laravel 中更改默认路径“/public”名称
【发布时间】:2017-04-13 17:09:31
【问题描述】:

我的服务器使用 cPanel。这里的目录结构

  • laravel 项目
  • public_ftp
  • public_html
    • 公开
      • index.php

我跟随这个人部署在服务器上 https://github.com/petehouston/laravel-deploy-on-shared-hosting

一切正常,但我的基本路径是“mydomain.com/public” 我不想从我的路径中删除 /public 而是要更改它, 我想要这样的路径“mydomain.com/noticed”

我使用的是 laravel 5.3 版

有什么想法吗? 谢谢你

【问题讨论】:

    标签: laravel-5


    【解决方案1】:

    It was suggested 更改公共文件夹中的index.php

    *
    |--------------------------------------------------------------------------
    | Turn On The Lights
    |--------------------------------------------------------------------------
    |
    | We need to illuminate PHP development, so let us turn on the lights.
    | This bootstraps the framework and gets it ready for use, then it
    | will load up this application so that we can run it and send
    | the responses back to the browser and delight our users.
    |
    */
    
    $app = require_once __DIR__.'/../bootstrap/app.php';
    
    // set the public path to this directory
    $app->bind('path.public', function() {
        return __DIR__;
    });
    

    现在你不需要改变你的公共路径,当你的公共 目录已更改。

    Elixir 有一个硬编码的公共路径!不要忘记设置更改 Elixir 配置中的公共路径。

    我可能会补充一点,您还需要确保您的新公共路径具有与默认路径相同的权限。您可能还想更改 config/filesystem.php 中的公共路径。

    【讨论】:

    • 我使用asset() 来包含来自js/css 的源代码,然后就全部消失了。我关注这个stackoverflow.com/a/29716810/5071013 并将asset() 更改为elixir() 仍然不起作用
    • 哦,我的 XAMMP 出了点问题,但生产工作还可以,谢谢 :D
    【解决方案2】:

    在 laravel 5.6 中将此代码添加到 bootstrap/app.php :

    $app->bind('path.public', function() {
        return realpath(__DIR__.'/../');
    });
    

    其中 __DIR__.'/../' 是您的公用文件夹的路径

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-22
      • 2014-06-18
      • 1970-01-01
      • 1970-01-01
      • 2017-01-15
      • 2010-09-17
      相关资源
      最近更新 更多