POST redirect: different behavior in index.php vs included files

Any ideas on what could cause this first example to work and the second example to fail? I got as far as determining that the behavior depends only on where I stick the one line of code that triggers the redirect: it works in my main index.php file, and it fails when I put it at the end of the included code in another file. I’m using Apache webserver, I’ve got the files owned apache:apache and chmod 664, I changed the security context:
sudo chcon -R system_u:object_r:httpd_sys_content_t:s0 /var/www/secure/dev/{all my projects}

Example 1: this works

within index.php:
$app->post(’/add/template’, function ($request, $response, $args) {
require_once ‘…/app/routes/add_template__post.php’;
return $response->withStatus(303)->withHeader(‘Location’,$url);
});

within ./app/routes/add_template__post.php
(some stuff)

Example 2: this fails

within index.php:
$app->post(’/add/template’, function ($request, $response, $args) {
require_once ‘…/app/routes/add_template__post.php’;
});

within ./app/routes/add_template__post.php
(some stuff - exacty the same)
return $response->withStatus(303)->withHeader(‘Location’,$url);

I should clarify what I mean by “it fails.”

What I observe is that my web browser does not redirect- just has empty content. My Apache access logs show a 200 OK response, and this is consistent with what I see using ‘ngrep’ to sniff the traffic from command line on the webserver.

Edit: I have confirmed this behavior change is repeatable with simply moving the location of a single line of code, from the last statement in an included file to the first line after the included file in the $app->get closure that calls it. Other commands in the included file are verified to run, so it is not a simple file permission or ownership thing.

did you ever figure out what was happening? i have something similar,
after i upgraded my slim version, redirects from within middleware result in the same output
i get the no redirect behaviour with an empty response body

if you set your response to a var and write directly to the body i bet you will see it on the screen

$response = $response->withStatus(303)->withHeader(‘Location’, $url);
$response->getBody()->write(‘foo’);
return $response;

what version of slim are you using? i think a bug may have been introduced somewhere above 3.8