Laravel Remove index.php from url
Hello Dev,
As we speak, i we’ll present you laravel take away index.php from url. This text offers you easy instance of laravel take away index.php from url. you’ll study laravel take away index.php from url.
On this artical i’ll present you laravel take away index.php from url. We will use this instance in Laravel 6, Laravel 7, Laravel 8. So let’s observe few step to create instance of laravel take away index.php from url.
app/Suppliers/RouteServiceProvider.php
<?php namespace AppProviders; use IlluminateCacheRateLimitingLimit; use IlluminateFoundationSupportProvidersRouteServiceProvider as ServiceProvider; use IlluminateHttpRequest; use IlluminateSupportFacadesRateLimiter; use IlluminateSupportFacadesRoute; use IlluminateSupportStr; class RouteServiceProvider extends ServiceProvider { /** * The trail to the "residence" route in your utility. * * That is utilized by Laravel authentication to redirect customers after login. * * @var string */ public const HOME = '/residence'; /** * Outline your route mannequin bindings, sample filters, and many others. * * @return void */ public operate boot() { $this->removeIndexPHPFromURL(); $this->configureRateLimiting(); $this->routes(operate () { Route::prefix('api') ->middleware('api') ->namespace($this->namespace) ->group(base_path('routes/api.php')); Route::middleware('internet') ->namespace($this->namespace) ->group(base_path('routes/internet.php')); }); } /** * Write code on Methodology * * @return response() */ protected operate removeIndexPHPFromURL() { if (Str::accommodates(request()->getRequestUri(), '/index.php/')) { $url = str_replace('index.php/', '', request()->getRequestUri()); if (strlen($url) > 0) { header("Location: $url", true, 301); exit; } } } /** * Configure the speed limiters for the applying. * * @return void */ protected operate configureRateLimiting() { RateLimiter::for('api', operate (Request $request) { return Restrict::perMinute(60)->by(elective($request->person())->id ?: $request->ip()); }); } }
now when you open url like bellow then:
https://instance.com/index.php/contact-us
will redirect to:
https://instance.com/contact-us
I hope it will probably assist you…
Komentar
Posting Komentar