【问题标题】:Laravel 5 & Vue components – Remove Public from URLLaravel 5 & Vue 组件 – 从 URL 中移除 Public
【发布时间】:2020-06-18 06:58:02
【问题描述】:

我有一个带有 Vue 组件的 Laravel 5 项目。该项目运行良好。

但我使用以下指令从路径中删除了“/public”:Remove /public from URL

现在 vue 组件不工作了。我需要修改哪些文件才能恢复 Vue 组件?

【问题讨论】:

    标签: laravel vue.js laravel-5


    【解决方案1】:

    我自己回答。

    我希望这不会影响我的状态。请管理员告诉我...

    修改后我需要像这样更改 .htaccess:

    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]
    
    RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !^/public/
    RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]
    

    这样静态文件组件将不会被忽略。像这样的组件再次工作

    【讨论】:

      【解决方案2】:

      让我分享我的经验。 在公用文件夹内,有 .htaccess 文件。 您可以将其复制到项目目录中。 在 vendor/laravel/src/Illuminate/Foundation/Helpers.php 中,像这样更改资产文件。

       function asset($path, $secure = null)
       {
           return app('url')->asset("public/".$path, $secure);
       }
      

      触摸 src 文件有些不好,但它总是运行良好。 希望对你有帮助。

      【讨论】:

      • 可能有效。我没试过。我一直认为您不应该触摸 /vendor 中的任何内容。 /vendor 目录中的所有内容只能由 composer 处理。
      猜你喜欢
      • 1970-01-01
      • 2015-10-11
      • 2016-07-30
      • 2016-01-10
      • 2021-09-27
      • 1970-01-01
      • 2015-01-14
      • 2020-06-07
      • 1970-01-01
      相关资源
      最近更新 更多