将表单发布到'/'获得301

At the root of the project ('/') I have a dashboard kind of page that is routed to 'Patterns:: index'. This works fine for loading the page with a GET, but I also have a form on this page that I want to send a POST request to the same action.

config/routes.php

Router::connect('/', 'Patterns::index');

The form create line on the view looks like so:

<?= $this->form->create($filter, ['url' => ['Patterns::index'], 'method' => 'post']) ?>

Note: it has also looked like this, but it didn't work either:

<?= $this->form->create($filter) ?>

The action that is generated by this form is the correct path to the project '../client-name' (the root), with a method of POST. But when I hit submit it tries to send the request to this route and gets a 301 then redirects to '../client-name/' (note the trailing forward slash).

If I manually edit the action in the browser in the HTML to have the trailing forward slash the request goes through as expected - It sends a POST request to 'Patterns::index'.

Something else to note is that if I remove the line in config/routes and just access it by going to '/patterns' everything works as intended...

Can someone point me in the right direction?

It is probably your web server and not Lithium that is causing the 301 redirect. You may have a physical folder named client-name in the web root. Your web server will automatically add the slash then as it intends to serve the index inside that folder. Another possibility is that your web server (apache? or nginx?) has a rewrite rule somewhere that does a 301 redirect to any url that doesn't have a trailing slash.

Lithium uses the PHP_SELF environment variable to determine the base folder in the lithium\action\Request::_base() method.

The url for the form action is generated via the lithium et\http\Router::match() method. There is a line in the code that strips all trailing slashes: https://github.com/UnionOfRAD/lithium/blob/7251cc28/net/http/Router.php#L434

So Lithium is definitely biased towards urls that don't have a trailing slash. That limitation could warrant filing an issue in the project's github repository. If you edit the Router.php file in the framework and add this after the line that trims the path, it would always include the trailing slash for url paths without a suffix (i.e. file extension):

if (!$suffix && $path !== '/') {
    $path .= '/';
}

I'm not sure if there's another way. IIRC, when I encountered this problem in a project, I moved the physical folder to a different location so my web server wouldn't issue the 301 redirect.