[英]Laravel URL rewrite cascade or forward to route for same pattern URLs
I am facing a problem with URLs having same structure but serving different resources. 我遇到的URL具有相同结构但服务于不同资源的问题。 Consider example Below:
考虑下面的示例:
GET /mumbai/mobiles GET /travel/best-getaways-from-delhi
now in my routes.php I have Rule definition as below: GET /mumbai/mobiles GET /travel/best-getaways-from-delhi
现在在我的route.php中,我的规则定义如下:
Route::get('/{city}/{category}', array( 'as' => 'citySearch', 'uses' => 'SearchController@doSearch' ));
Route::get('/{category}/{pageSlug}', array( 'as' => 'pageUrl', 'uses' => 'pageController@pageView' ));
Obviously, If I request /travel/best-getaways-from-delhi
it'll match first rule and I won't be able to serve the content. 显然,如果我请求
/travel/best-getaways-from-delhi
它将匹配第一条规则,而我将无法提供内容。 My Logic here is either I can write a filter/or in controller a code which will lookup all cities and if there is no city ( ie travel is no city) it'll forward my requests to second rule ( pageUrl
). 在这里,我的逻辑是我可以编写一个过滤器,或者在控制器中编写一个可以查询所有城市的代码,如果没有城市(即旅行没有城市),它将把我的请求转发给第二条规则(
pageUrl
)。 How can I do that? 我怎样才能做到这一点? or can anyone suggest me a better approach.
或有人可以建议我一种更好的方法。 Thanks
谢谢
I would add a prefix to the URL to differentiate. 我将在URL前面添加前缀以区别。 For example have the links like
/city/mumbai/mobiles
and /page/travel/best-getaways-from-delhi
例如,具有
/city/mumbai/mobiles
和/page/travel/best-getaways-from-delhi
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.