In Apache it is possible to redirect everything to the closest index.php, using .htaccess
Example folder structure:
/Subdir
/index.php
/.htaccess
/Subdir
/Subdir/.htaccess
/Subdir/index.php
If I access /something it will redirect to the root index.php, and if I access /Subdir/something it will redirect to Subdir/index.php
Can this be done in nginx as well?
It should be possible, because in nginx documentation it says If you need .htaccess, you’re probably doing it wrong :)
I know how to redirect everything to the root index.php:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
But how to check for index.php in every parent directory until / ?
edit:
I found that these rules do what I want:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /Subdir{
try_files $uri $uri/ /Subdir/index.php?$query_string;
}
But is there a way to make it abstract, like
location /$anyfolder{
try_files $uri $uri/ /$anyfolder/index.php?$query_string;
}
?