【发布时间】:2015-04-20 12:39:02
【问题描述】:
是否可以在 Laravel 5 的 routes.php 文件而不是我的 .htaccess 文件中执行 URL 重写?我知道重定向很容易,但我最好避免这样做,以便将短网址保留在地址栏中。
假设我有将使用该路由的 url 'http://website.com/store/clothing/shites/cool-shirt':
Route::get('store/{category}/{subcategory}/{product}', [
'uses'=>'StoreController@getProduct'
]);
我想创建一个快捷方式 URL 'http://website.com/cool-shirt',它会从数据库表中获取完整的 url,然后调用正确的路由和参数(无需重定向)。
Route::get('{slug}', function($slug){
$shortcut = \App\Shortcut::whereSlug($slug)->first();
// I'm making the execute_route() function up here
return execute_route($shortcut->full_url);
})
基本上在路由中调用路由。
这可能吗?
【问题讨论】: