Hey friend, I was having the same problem. Tried my best to make it work with htaccess, but failed miserably, since I'm not htaccess expert.
This is my old htaccess post and David's suggestion.
For now I've made a PHP solution in my "bootstrap" file, until I find a better one. It's working, so if you fail with htaccess too, you can use it :)
Sample url for our test: https://localhost/framework-v1.0/public/api/v1/documentation/news
$redirect = false;
// 301 Redirect if /public/index.php (this only shows homepage so just redirect to real homepage)
$currentUrl = getCurrentUrl(); // My custom function which returns: https://localhost/framework-v1.0/public/api/v1/documentation/news
$currentPath = str_replace($config->site->url, '', $currentUrl); // Result: api/v1/documentation/news
if (strpos($currentUrl, 'public/index.php') !== false) {
$redirect = $config->site->url; // In my case $config->site->url is https://localhost/framework-v1.0/
}
// 301 Redirect if /public/ - Replace only the first occurance of /public/ (Redirect to same url but without the first /public/ in it)
if (substr($currentPath, 0, 6) == 'public') {
$needle = '/public/';
$redirect = substr_replace($currentUrl, '/', strpos($currentUrl, $needle), strlen($needle));
// Result with correct url: https://localhost/framework-v1.0/api/v1/documentation/news
}
if ($redirect) {
return $di->getResponse()->redirect($redirect, true, 301)->send();
}
PS1: I think you can do something with the server configuration, but since in most cases I don't have access to the server I can't afford to go this path.
PS2: If you find a better solution please update the post to help others.