Fix wrong behavior when index file matches directory