管腔柱扎根而不落后斜线会导致301重定向拖延斜线
我需要使用Laravel的管腔来创建一些微型服务。在这种情况下,我需要获取并发布到应用程序的根路由(“/”),以获取课程列表并创建新课程。
我的web.php
看起来像这样:
$router->get("/", "ApiModule@list");
$router->get("/{id}", "ApiModule@read");
$router->post("/", "ApiModule@create");
$router->put("/{id}", "ApiModule@update");
$router->delete("/{id}", "ApiModule@delete");
当我提出请求时(与Chrome的控制台一起进行邮递员,Insomnia和JS获取),POST/
Route 拖延斜线,它将301状态代码重定向到get/
,带有尾巴斜线,失去了我的原始请求。但是,当我在尾随的斜线的情况下进行post/
request 时,它可以按预期工作。而且,这种行为不会在get /< /code>请求上发生(即使有或不带有落后斜线,它也可以按预期工作)。
因此,在管腔中,有一些将邮政请求重定向到root uri以获取请求,从而破坏了预期的行为。
我尝试修改/public/.htaccess
文件,在“如果不是文件夹...”部分中添加重新定位。我的.htaccess文件现在看起来像这样:
[...]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteCond %{REQUEST_METHOD} GET
RewriteRule ^ %1 [L,R=301]
[...]
但是静止不起。
有人可以帮我吗?我需要邮政请求才能root地址即使在URL中有或不带有拖延的斜线。除根以外的其他途径还可以正常工作。此问题仅在根路由下面临(“/”)。已经尝试使用空字符串而不是“/”(这样:$ router-&gt; post(“”,“”,“ apimodule@create”)
),但已尝试声明该路线,但也行不通。
谢谢!
I need to use Laravel's Lumen to create some microsservices. In this scenario, I need to GET and POST to the root route ("/") of my application, to get a list of courses and create a new course, respectively.
My web.php
looks like this:
$router->get("/", "ApiModule@list");
$router->get("/{id}", "ApiModule@read");
$router->post("/", "ApiModule@create");
$router->put("/{id}", "ApiModule@update");
$router->delete("/{id}", "ApiModule@delete");
When I make a request (tested with Postman, Insomnia and JS fetch through Chrome's console), the POST /
route without a trailing slash, it redirects with 301 status code to GET /
with a trailing slash, loosing my original request. But, when I make a POST /
request with a trailing slash, it works as expected. And, this behaviour doesn't happen on GET /
requests (even with and without a trailing slash, it works as expected).
So, in Lumen, there is something that redirects POST requests to root uri to GET requests, breaking the expected behaviour.
I've tried to modify the /public/.htaccess
file, adding a RewriteCond to the "Redirect Trailing Slashes If Not A Folder..." section. My .htaccess file looks like this now:
[...]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteCond %{REQUEST_METHOD} GET
RewriteRule ^ %1 [L,R=301]
[...]
But stills not working.
Can someone help me with this? I need POST requests to root address to work even with and without a trailing slash in URL. Other POST requests to any other route than root works fine. This problem is faced only with root route ("/"). Already tried to declare the route with an empty string instead of "/" (this way: $router->post("", "ApiModule@create")
), but doesn't work too.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以执行此类操作
yourlumenFolder/public
请参阅下面的代码。You can do something like this
yourLumenFolder/public
see below code.