first question:
i already remove index.php, but i want remove /web also. this is my .htaccess
RewriteEngine on
# If a
Using str_replace('/frontend/web', '', (new Request)->getBaseUrl()) for detecting base URL is a bad idea and using str_replace('/web', '', (new Request)->getBaseUrl()) is a terrible idea. str_replace() removes all occurences of requested string, so str_replace('/frontend/web', '', (new Request)->getBaseUrl()) for URL /frontend/web/tools/frontend/webalizer will give you /toolsalizer. Definitely not a thing that you want.
If you want to remove this string only from the begging of URL:
$baseUrl = (new Request())->getBaseUrl();
if ($baseUrl === '/frontend/web') {
$baseUrl = '';
} elseif (strncmp($baseUrl, '/frontend/web/', 14) === 0) {
$baseUrl = substr($baseUrl, 13);
}
But the best solution would be avoiding the whole problem in the first place, for example by using symlinks to mimic required directory structure for single webroot.