无法访问 Laravel 中共享主机中的符号链接文件

Cannot access symlinked file in shared hosting in Laravel

我使用托管服务,我的父托管目录中有两个文件夹

  1. 我的-laravel-应用程序文件夹
  2. public_html

public/index.php我改了

  1. require __DIR__.'/../vendor/autoload.php'; require __DIR__.'/../my-laravel-app-folder/vendor/autoload.php';
  2. $app = require_once __DIR__.'/../bootstrap/app.php'; $app = require_once __DIR__.'/../my-laravel-app-folder/bootstrap/app.php';

在public/.htaccess文件我改了

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On
    Options +FollowSymLinks


    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l

    RewriteRule ^ index.php [L]
</IfModule>

从父/目录,我已经运行

ln -s my-laravel-app-folder/storage/app/public public_html/storage

但我仍然无法访问链接的存储文件并出现 404 错误。

最后我找到了解决方案,就是在创建符号链接时,我必须包含文件夹的绝对路径而不是当前路径。例如,

  • 对于 my-laravel-app-folder/storage/app/public 替换为 /home/u440262284/domains/mysite.com/my-laravel-app-folder/storage/app/public 而不是
  • 也将 public_html/storage 替换为 /home/u440262284/domains/mysite.com/public_html/storage

成功了!!!

做符号链接

ln -s my-laravel-app-folder/storage/app/public public_html/storage

删除 index.php.htaccess 文件 public_html/storage你的laravel项目手动复制public_html/storage。 您不需要更改您的index.php文件,请尝试将您的域路径更改为public_html/storage/public