laravel 路由如何寫,才能實現 /post 和 /post/ 指向一個位置?

來源:互聯網
上載者:User
現在,/post/總會跳到別的頁面,而不是跳到/post的位置。

我的laravel版本是4.2,下面是測試代碼。

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'; });

以上兩種配置,結果都如下,都是/post/ 301 跳到別的頁面,/post頁面正常。

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

Moved Permanently

The document has moved here.

回複內容:

現在,/post/總會跳到別的頁面,而不是跳到/post的位置。

我的laravel版本是4.2,下面是測試代碼。

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'; });

以上兩種配置,結果都如下,都是/post/ 301 跳到別的頁面,/post頁面正常。

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

Moved Permanently

The document has moved here.

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

會嗎?L5 Route組件的行為我記得是:

  1. 無論帶結尾斜線與否,均視為同一個路由;
  2. 帶斜線的301跳轉到不帶斜線的(至少對GET如此);
  3. 同一個路由指定兩次時,後邊的覆蓋前邊的。

以下是測試案例與結果:

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/這裡Web server提示了301跳轉到 http://test1.l5.invalid/postSF的前台渲染有誤,結果見 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/這裡Web server提示了301跳轉到 http://test1.l5.invalid/postSF的前台渲染有誤,結果見 http://pastebin.com/ZMh0smvq$ curl http://test1.l5.invalid/postwith slash

因為 /post/和/post 是兩個路由路徑, 要讓他倆指向一個位置,分配配置他倆,都指向同一個位置。

Laravel不知道,不過其他路由我都是後邊加?的
/post/?

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.