3

I want all the links on my site to use HTTPS; however I cannot (for non technical reasons) force users to use HTTPS. I therefore want all URLs generated by Laravel to be prefixed with 'https', but I don't want Laravel to throw an exception if a user visits the URL over 'http'.

I have the following route setup:

Route::get('dashboard', [ 'uses'=>'DashboardController@view' ]);

Can anyone tell me how to get URL::route('dashboard') to return a HTTPS version of the URL, without rewriting my route as:

Route::get('dashboard', [ 'https', 'uses'=>'DashboardController@view' ]);

Or how to write my route as per the second example, but not thrown an exception if then accessed over 'http'?

Neil
  • 105
  • 1
  • 3
  • 8
  • I would use mod_rewrite http://stackoverflow.com/questions/4398951/force-ssl-https-using-htaccess-and-mod-rewrite – Dave Dec 16 '13 at 15:49
  • Sorry – to confirm I'm not trying to stop users accessing the site via HTTP – I'm trying to change the response of `URL::route` such that it returns a secure link, without adding ‘https’ as a parameter to the route. – Neil Dec 18 '13 at 13:32
  • Hey Neil, I agree. I need to know how to force URL::route to create secure links because our load balancer is doing the HTTPS and then passing the request to our server as standard HTTP. The comments here to not answer the question. Hope someone can help!! – Artistan Mar 21 '14 at 14:46
  • Hi @Artistan. I dug into the source code to look at this. As it's currently built (or at least there as it was built 3 months ago), there is no way to do this. I'll take another look now we have 4.1 to see if anything has changed – or indeed whether I can come up with a patch to submit that would allow it. – Neil Mar 21 '14 at 18:32
  • apparently there is a server config to get the server to act as though it is https even though it is not. So i have a "fix", thanks! – Artistan May 02 '14 at 11:46

1 Answers1

1

For creating an https link in a laravel blade view with URL::route , simply use: URL::secure()

http://cheats.jesse-obrien.ca/#urls

URL::secure('foo/bar', $parameters);
URL::secureAsset('css/foo.css');
URL::to('foo/bar', $parameters, $secure);
Maurice
  • 1,342
  • 11
  • 21