RedirectMatch how to match any words but not index and nothing
You may add a new rule below your existing rule:
RewriteCond %{THE_REQUEST} \s(/folder/[\w-]+)\.php[?\s] [NC]
RewriteRule ^ %1/ [L,R=301]
THE_REQUEST
matches only original URI sent by client, it won't match modified REQUEST_URI
.
I found this question: Match everything except for specified strings that help me to fix regex.
RedirectMatch permanent /folder/(?!.*(index))(.*)\.php https://www.site.it/folder/$2/
This rule match everything except index so redirect /folder/page.php
only once to /folder/page/
but unfortunately, as @anubhava pointed out, this rule doesn't match any page name that contains index.
After further dig, I found this solution:
RedirectMatch permanent /folder/(?!index.php$|$)(([\w-]+)\.php$) https://www.site.it/folder/$2/
Anyway thanks to @anubhava that support me.