为 Laravel 路由添加 url 扩展
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22287649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add url extensions to Laravel routes
提问by bman
Is it possible to add an extension to laravel routes like so?
是否可以像这样为 Laravel 路由添加扩展?
http://www.mywebsite.com/members/login.html
http://www.mywebsite.com/members/login.html
and another page with a different extension
和另一个具有不同扩展名的页面
http://www.mywebsite.com/contactus.htm
http://www.mywebsite.com/contactus.htm
I am transitioning an old website into laravel but the owner doesn't want to change the URL for SEO purposes.
我正在将旧网站转换为 laravel,但所有者不想出于 SEO 目的更改 URL。
回答by Simo A.
Yes, this is certainly possible and very straightforward to do with Laravel.
是的,这对于 Laravel 来说当然是可能的并且非常简单。
routes.php:
路线.php:
Route::get('members/login.html', function() { return View::make('members.login'); } );
Then you need to create the view members/login.phpor members/login.blade.phpin your views
directory.
然后您需要在您的目录中创建视图members/login.php或members/login.blade.phpviews
。
回答by Tariq
Route::get('{id}-{another_id}.html', 'Controller@view')
->where('id', '.*?')
->where('another_id', '\d+');
Something like this
像这样的东西