nature
nature

Reputation: 307

Laravel 5.4 optimizing redirect 301

I am creating some permanent redirects in laravel 5.4 and I want to know if this is the best way to do it and how to optimize this code. I saw in this answer Optimize Redirect 301 for a multilingual site an example in .htaccess but how to do the same in routes? and what is better, do it in routes or in .htaccess?

I've put this in routes:

Route::get('es/nosotros/quienes/quienes.php', function(){ return Redirect::to('quienes', 301); });
Route::get('en/nosotros/quienes/quienes.php', function(){ return Redirect::to('quienes', 301); });
Route::get('pt/nosotros/quienes/quienes.php', function(){ return Redirect::to('quienes', 301); });

Another question is that I have to redirect about 5,000 urls. As a final result, I'm going to get a file with the 5,000 old urls and the 5,000 new urls. Do I also include it in the routes file? In the .htaccess? Thanks.

Upvotes: 0

Views: 1081

Answers (1)

Simone Cabrino
Simone Cabrino

Reputation: 931

Why not using a placeholder?

Route::get('{lang}/nosotros/quienes/quienes.php', function ($language) {
    return Redirect::to('quienes', 301)->with('language', $language);
});

The difference between routes and .htaccess is speed: the second one will not pass information to the application and the redirect answer will be received directly from the webserver (Apache). Server will thanks you!

Upvotes: 1

Related Questions