Laravel Redirect With Trailing Slash

I’ve recently had to set up some redirects using Laravel 4.2 that had a trailing slash… if you’ve ever had to do this on Laravel then you know it isn’t as straightforward as the rest of the framework is.

Normally when writing a redirect to a URL outside of my application but inside of my domain I’ll do this and it works fine:

Redirect::to('example/page', 301);

When redirecting to a page that requires a trailing slash:

Redirect::to('example/page/', 301);

Laravel strips the trailing slash and just sends me to example/page instead of example/page/. I had even tried this:

Redirect::to('example/page' . '/', 301);

My solution is to use the following:

Redirect::to('example/page' . '\/', 301);

The solution isn’t very elegant but it gets the job done.

Related Posts

How to View Last Query in Laravel 4
Ubuntu 14.04 Composer Mcrypt Error
© 2014 - 2021 · Home ·