How can I write a laravel route to achieve/post and/post/point to a location?

Source: Internet
Author: User
Now, the post will always jump to another page, rather than to the position of post. My laravel version is 4.2. below is the test code. {Code...} and the above two configurations are as follows: both of them are post301 jump to another page, and the post page is normal. {Code...} Now,/post/will always jump to another page, instead of to/post.

My laravel version is 4.2. below is the test code.

phpRoute::get('post', function() { return 'w/out slash'; });Route::get('post/', function() { return 'with slash'; });
phpRoute::get('post/', function() { return 'with slash'; });Route::get('post', function() { return 'w/out slash'; });

The results of the above two configurations are as follows:/post/301 is redirected to another page, and the/post page is normal.

curl http://localhost/gitcafe/public/postwith slashcurl http://localhost/gitcafe/public/post/301 Moved PermanentlyMoved Permanently

The document has moved here.

Reply content:

Now,/post/always jumps to another page, instead of to/post.

My laravel version is 4.2. below is the test code.

phpRoute::get('post', function() { return 'w/out slash'; });Route::get('post/', function() { return 'with slash'; });
phpRoute::get('post/', function() { return 'with slash'; });Route::get('post', function() { return 'w/out slash'; });

The results of the above two configurations are as follows:/post/301 is redirected to another page, and the/post page is normal.

curl http://localhost/gitcafe/public/postwith slashcurl http://localhost/gitcafe/public/post/301 Moved PermanentlyMoved Permanently

The document has moved here.

Http://stackoverflow.com/questions/22063520/laravel-slash-after-url-re...

Yes? L5RouteThe behavior of components is as follows:

  1. The same route is considered whether it has an ending slash or not;
  2. Jump to a non-diagonal line (at leastGETSo );
  3. When the same route is specified twice, the back side overwrites the front side.

The following are test cases and results:

Case 1
$ Diff my_l5_app/app/Http/routes. php l5_fresh/app/Http/routes. php22, 24d21 <Route: get ('Post/', function () {return' with slash ';}); <Route: get ('post ', function () {return 'w/out slash';}); $ curl http://test1.l5.invalid/post/here the Web server prompts 301 jump to login http://pastebin.com/ZMh0smvq$ curl http://test1.l5.invalid/postw/out slash

Case 2

$ Diff my_l5_app/app/Http/routes. php l5_fresh/app/Http/routes. php22, 24d21 <Route: get ('post', function () {return 'W/out slash ';}); <Route: get ('Post /', function () {return 'with slash';}); $ curl http://test1.l5.invalid/post/here the Web server prompts 301 jump to login http://pastebin.com/ZMh0smvq$ curl http://test1.l5.invalid/postwith slash

Because/post/AND/post are two route paths, you need to point them to one location and assign the configuration to both of them to the same location.

Laravel doesn't know, but I add other routes to the backend? Of
/Post /?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.