lundi 28 septembre 2020

Hide url segment in Laravel using htaccess (routes with the same number of segments)

I have these routes in web.php

Route::get('/book/{book}', booksController@show);
Route::get('/user/{user}', UsersController@show);
Route::get('/{category}', CategoriesController@show);

I want to hide book and user from url using htaccess as long as they can't be removed in routes. I tried this in both /.htaccess and in /public/.htaccess but none have worked

RewriteEngine on
RedirectMatch 301 /book/(.*) /$1

RewriteEngine on
RewriteRule ^/book/(.+)$ /$1 [L,QSA]

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ book/$1 [L]

when I visit a url contains the word book it doesn't get removed it's always there. Now how can I have all three routes without any static word like book or user without any conflict to be like this

Route::get('/{book}', booksController@show);
Route::get('/{user}', UsersController@show);
Route::get('/{category}', CategoriesController@show);


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire