[英]Remove public from URL Laravel 5.3
將htaccess和index.php文件從公共文件夾復制到根目錄,然后更改root index.php代碼,如下所示
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
安裝Laravel后,應將Web服務器的文檔/ Web根目錄配置為公共目錄。 此目錄中的index.php用作進入應用程序的所有HTTP請求的前端控制器。
https://laravel.com/docs/5.3/installation#configuration
不要編輯.htaccess
或Laravel相關文件,只需將Web服務器指向public
目錄而不是Laravel項目目錄 :
DocumentRoot "/path_to_laravel_project/public"
<Directory "/path_to_laravel_project/public">
然后重啟Apache。
在root中添加.htaccess
文件,其中包含 -
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
在根目錄中創建.htaccess文件並將以下內容放入其中
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
公眾沒有出現在laravel的url中你正在強迫laravel操縱它的結構。 為了擺脫進一步的問題,一個好的建議是,而不是使用xampp作為根目錄中的默認服務器運行命令。
php artisan serve
甚至上面的解決方案工作,但我建議不要這樣做。 這就是原因所在。
- 您應該將Apache主機根目錄指向$ LARAVEL_PATH / public目錄而不是$ LARAVEL_PATH。
- 你必須為用戶配置apache,不能訪問.env,git文件,配置文件夾的文件
公共目錄是有理由使項目更安全。 解決實際問題,不要試圖打破這個簡單但很好的安全性添加。
將所有文件和文件夾從公用文件夾復制到根文件夾,然后將.htaccess
文件編輯為
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
並且不要忘記更改index.php文件中的路徑。 有關詳細信息,請參閱以下鏈接
https://ellislab.com/forums/archive/viewthread/151342/#734511
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.