不重复到Laravel,如何重定向为301和302:
我在Apache web服务器上使用Laravel 4.1, php 5.4。我想重定向到
的所有请求 http://www.example.com/whateva
to
http://example.com/whateva
我正在计算我的规范URL,以放置在Head部分,如下所示:
$canonicalURL = Request::url() . $url_param;
$canonicalURL = str_replace("http://www.example.com","http://example.com", $canonicalURL);
如何重定向?
很抱歉打扰你,但我现在找到答案了。
我在我的app/filter.php
App::before(function($request){
//Remove the 'www.' from all domains
if (substr($request->header('host'), 0, 4) === 'www.') {
$request->headers->set('host', 'example.com');
return Redirect::to($request->path());
}
});
像魅力一样工作,没有其他需要做的。