How do I make Laravel 5.3 create route URLs with trailing slashes?
The route is defined as
Route::get('/home/', ['as' => 'home', 'uses' => 'HomeController@index']);
I then create the url with the route helper function in a view:
{{ route('home') }}
This creates http://localhost:8000/home
instead of http://localhost:8000/home/
.
This question is very similar to Laravel - append a trailing slash in routes, but that question doesn't have an answer either and it seems to me that my description is a tat shorter.
Edit: The two possible naming methods from the docs don't make a difference:
Route::get('/home/', ['as' => 'home', 'uses' => 'HomeController@index']);
Route::get('/home/', 'HomeController@index')->name('home');
Laravel includes a block of code in its . htaccess file that redirects any url with trailing slash to non slashed url by default if the uri is not pointing to a directory. You can remove that piece of code and it should work fine in case you've appended a slash to each laravel route manually.
Historically, a trailing slash marked a directory and a URL without a trailing slash at the end used to mean that the URL was a file. Today, however, trailing slashes are purely conventional, and Google does not care whether you use them; as long as you're consistent.
Email Subscription. A trailing slash is a forward slash (“/”) placed at the end of a URL such as domain.com/ or domain.com/page/. The trailing slash is generally used to distinguish a directory which has the trailing slash from a file that does not have the trailing slash.
For a start it is using a named route. This means that the link between the form and its controller are not dictated by the url that the user sees. The next advantage is that you can pass additional parameters into the route helper and it will put those in the correct place in the form action.
The marked variant is more similar to a crutch than to the decision as URL is in sitemap.xml and still anywhere therefore in this case, it is better to edit everything only in the directory routes/*.php, That is all same the variant with UrlGenerator
census will be the most correct. In this case, there is a very useful package (illuminatech/url-trailing-slash
) that essentially should solve this problem. All changes will be only at the routing level.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With