Make rootPath part of regex greedy

- Fixes #10977
- Also replaced `isset() && true` with simple `!empty()` which is equivalent.