【发布时间】:2023-04-09 20:02:01
【问题描述】:
我已经尝试更改 .htaccess 文件,尝试了几种解决方案,但没有任何效果。每当我向 URL 添加尾部斜杠时,它会打开另一个页面,这不应该发生,向 URL 添加尾部斜杠应该将其重定向到没有尾部斜杠的 URL。我尝试了以下解决方案:
我想要实现的是 http://127.0.0.1:8080/login/ 应该为我的应用程序中的每个 URL 重定向到 http://127.0.0.1:8080/login。
public/.htaccess
<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
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [R=301,L]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
routes/web.php
<?php
use Illuminate\Support\Facades\Route;
// Navigation Menu
Route::get('advisor', 'AdvisorController@index');
Route::get('investment', 'InvestmentController@index');
Route::get('investor', 'InvestorController@index');
Route::get('product', 'ProductController@index');
Route::get('rate', 'RateController@index');
// Stop registration other functions
Auth::routes([
'register' => false, // Registration Routes...
'reset' => false, // Password Reset Routes...
'verify' => false, // Email Verification Routes...
]);
// Login
Route::get('/', function () {
return redirect('login');
});
// Dashboard
Route::get('/home', 'HomeController@index')->name('home');
//admin users
Route::resource('/admin/users', 'Admin\UsersController', ['except' => ['show', 'create', 'store']]);
错误截图:
没有斜杠,我的应用程序 URL:
现在,如果我在 URL 中添加一个斜杠,我会得到:
【问题讨论】:
标签: php laravel .htaccess redirect