7

Is it possible to add an extension to laravel routes like so?

http://www.mywebsite.com/members/login.html

and another page with a different extension

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.

tereško
  • 58,060
  • 25
  • 98
  • 150
bman
  • 3,740
  • 9
  • 34
  • 40

2 Answers2

10

Yes, this is certainly possible and very straightforward to do with Laravel.

routes.php:

Route::get('members/login.html', function() { return View::make('members.login'); } );

Then you need to create the view members/login.php or members/login.blade.php in your views directory.

Simo A.
  • 1,330
  • 13
  • 18
  • what if there is optional url parameter at the end of url like: `Route::get('foo/{bar?}', function () {});` And I want to generate urls like these; `domain.com/foo.html` and `domain.com/foo/bar.html` – Behzadsh Oct 21 '15 at 14:13
  • This is still a very useful answer even after 9 years. Thanks @Simo – cd4success Aug 02 '23 at 01:29
2
Route::get('{id}-{another_id}.html', 'Controller@view')
        ->where('id', '.*?')
        ->where('another_id', '\d+');

Something like this

Tariq
  • 155
  • 5
  • 21