[英]Redirect Url Issue with Laravel and htaccess
我在本地 xampp 中為我的項目創建虛擬主機。 Url: http://kooltech-us.com/
我在公用文件夾(Laravel)中有文件夾的名稱 admin(來自下圖)。
在我的項目中,我的管理員登錄 url http://localhost/admin/login
。
I hit url http://localhost/admin/login
to go to admin login page.. it's okay.. but when i hit this http://localhost/admin
. 它帶我到 public/admin 文件夾。 這意味着向我展示公共目錄列表。
為了防止訪問目錄列表或公共/管理員,我在Options - Indexes
代碼。它通常給我 403 錯誤(禁止訪問。)。 這是工作。
當我點擊 url http://localhost/admin
時,我正在尋找它,它會將我帶到http://localhost/admin/login
。
筆記:
Options - Indexes
。 一般來說,這給了我 403 錯誤(禁止訪問。)。我寫在 web.php 但它不工作..
Route::get('/admin', function () {
return redirect('/admin/login');
});
如果需要更多解釋請評論..
To modify the .htaccess you would need to add something like this to your .htaccess This will redirect all request from /admin to /public but still show as /admin which will allow your redirect in web.php
to work:-
RewriteRule admin /public [L]
這會給你: -
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# 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
RewriteRule admin /public [L]
RewriteRule ^ index.php [L]
</IfModule>
但是我仍然覺得這是一種不好的做法,並且像@flakerimi 所建議的那樣更改目錄結構將是一個更好的解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.