我剛剛將 Laravel 應用程式部署到托管站點,并將其放入他們的檔案夾中,如下所示:
"example.com/public_html/{All files in a laravel directoy}"
現在,如果在瀏覽器中打開https://example.com它將顯示錯誤
Fatal error: require(): Failed opening required '/home/customer/www/example.com/public_html/public/../vendor/autoload.php' (include_path='.:/usr/local/php74/pear') in /home/customer/www/example.com/public_html/public/index.php on line 34
我的 routes/web.php 看起來像這樣:
Route::get('/', function () {
return redirect()->route('login');
});
我已經運行 composer install 并將 htaccess 添加到里面的 public_html 檔案夾
htacess,看起來像這樣
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR] RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]
我的 htaccess 是錯誤的嗎,或者如果使用 htaccess 將 index.php 指向公共檔案夾,Laravel 是否有任何其他設定?
注意:托管站點,將默認檔案根目錄設定為 public_html,我無法更改它。所以為了指向公共檔案夾,我需要創建 .htaccess 檔案
uj5u.com熱心網友回復:
將.htaccess檔案放置到您的根檔案夾并激活mod_rewrite.
這是檔案應包含的內容的示例,無需確定特定地址:
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
我認為由于條件規則,它在您的情況下不起作用。
uj5u.com熱心網友回復:
- 將 Laravel 內容復制到一個對外部隱藏的目錄中,不同于
public_html. 讓我們假設它是/home/user1/myapp. - 將 Laravel
public目錄的內容移動到public_html. 所以,你應該將/home/user1/myapp/public/*到example.com/public_html - 把里面的相對路由改成
index.php指向第一步的目錄。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/322373.html
