首页 > 解决方案 > Laravel 在斜杠上重定向 [ / ]

问题描述

Laravel 正在从OPTIONS方法重定向到GET方法。

web.php(路由)

Route::any('/files/{document?}','webDavController@dispatch')->name('webDav');

webDavController.php

private $allowMethods = array('options','get','head','post','delete','trace','propfind','proppatch','copy','mkcol','put');

public function dispatch(  $fileId = false  ){


        $method = strtolower($_SERVER['REQUEST_METHOD']);

        if(in_array($method, $this->allowMethods)){         
            switch ($method){
                case "get":
                    $this->getFile();
                    break;
                case "put":
                    $this->putFile();
                    break;
                case "options":
                    $this->getOptions();
                    break;
            }

        }

    }

阿帕奇访问日志

x.x.x.x - - [07/Jan/2020:10:49:37 -0500] "OPTIONS /files/ HTTP/1.1" 301 246 "-" "PostmanRuntime/7.21.0"
x.x.x.x - - [07/Jan/2020:10:49:37 -0500] "GET /files HTTP/1.1" 200 68280 "https://server.com/files/" "PostmanRuntime/7.21.0"

为什么会发生这种重定向?我该如何解决它,为什么要重写为GET?我按照其他用户的建议做了一个 apache mod-rewrite,但仍然存在问题,也许我做得不对。

标签: phplaravel

解决方案


推荐阅读