Как удалить index.php из URL в Laravel
Несколько вариантов удаления ненужного index.php из URL.
Laravel Service Provider:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
use Illuminate\Support\Str; class RouteServiceProvider extends ServiceProvider { public function map(Router $router) { $this->removeIndexPhpFromUrl(); } protected function removeIndexPhpFromUrl() { if (Str::contains(request()->getRequestUri(), '/index.php/')) { $url = str_replace('index.php/', '', request()->getRequestUri()); if (strlen($url) > 0) { header("Location: $url", true, 301); exit; } } } } |
Apache .htaccess
1 2 3 4 5 |
<IfModule mod_rewrite.c> RewriteEngine On # Redirect if index.php is in the URL RewriteRule ^index.php/(.+) /$1 [R=301,L] </IfModule> |
Nginx
1 2 3 |
if ($request_uri ~* "^/index\.php(/?)(.*)") { return 301 $1; } |
Recommended Posts
Не работает autocomplete в моделях Laravel
01.02.2022