![](/img/trans.png)
[英]How to remove trailing subfolder/public/index.php from the Laravel 9 website URL on shared hosting?
[英]Laravel shared hosting, index.php not pointing to root but staying at public_htmls
我一直致力於使用 cpanel 在共享主機上部署我的 Laravel 應用程序。 但是,我收到此錯誤:
[08-Sep-2018 07:38:43 UTC] PHP Fatal error: require(): Failed opening required '/home/daankraa/public_html/../../supersax/vendor/autoload.php' (include_path='.:/opt/cpanel/ea-php71/root/usr/share/pear') in /home/daankraa/public_html/index.php on line 24
從我這里看到的是,它不想切換到根目錄,而是一直在尋找:
/home/daankraa/public_html/../../supersax/vendor/autoload.php in public_html.
我試過用點向上移動一個目錄,但它不想。 我怎樣才能解決這個問題?
提前致謝!
大安
1) 將 .htaccess 從公用文件夾復制到根目錄
2) 將 server.php 重命名為 index.php
server.php 文件將在 root 中
簡單的 :)
將所有內容從 public 移動到根目錄和 public 文件夾的 index.php 文件,修改如下:
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
索引.php
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* @package Laravel
* @author Taylor Otwell <taylor@laravel.com>
*/
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
return false;
}
require_once __DIR__.'/public/index.php';
這是一個對我有用的非常簡單的方法:
在 public_html 文件夾中創建一個 .htaccess 文件(該文件與 .env 文件級別相同)
將以下代碼復制並粘貼到 .htaccess 文件中
<IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews -Indexes </IfModule> RewriteEngine on # serve existing files in the /public folder as if they were in / RewriteCond %{DOCUMENT_ROOT}public%{REQUEST_URI} -f RewriteRule (.+) /public/$1 [L] # route everything else to /public/index.php RewriteRule ^ /public/index.php [L] </IfModule>
保存文件。 這就是您現在可以訪問您的網站www.example.com
注意:出於某種原因,如果它不起作用,您的文檔根目錄可能會有所不同,您將不得不使用要替換的公共文件夾的完整路徑:{DOCUMENT_ROOT} 與完整路徑 /var/www/example.com/ web,您可以通過在laravel的公共文件夾中創建一個名為get_doc_root.php的文件並在該文件中粘貼代碼來獲取完整路徑
<?php
echo getcwd();
獲取路徑后,您可以通過轉到www.example.com/public/get_doc_root.php來查看您的路徑,只需將其復制並替換您創建的 .htaccess 中的 {DOCUMENT_ROOT}。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.