現在,/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 PermanentlyMoved 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 PermanentlyMoved Permanently
The document has moved here.
http://stackoverflow.com/questions/22063520/laravel-slash-after-url-re...
會嗎?L5 Route組件的行為我記得是:
- 無論帶結尾斜線與否,均視為同一個路由;
- 帶斜線的301跳轉到不帶斜線的(至少對
GET如此);
- 同一個路由指定兩次時,後邊的覆蓋前邊的。
以下是測試案例與結果:
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/?