Redirects With Wildcards

Hello Community.

We have been learning and creating a website on goHugo and have access to user management as well. Currently we have two different kinds of users - Free and Pro.

We have managed to get all codes ready and set up. However, there is a requirement that we have not been to accomplish.

We have a folder fruits which contains several subfolders which are named by 2 letter codes (ex - ap for apple, ba for banana, and so forth). Now we want to provide role based access to the pages. To accomplish this we managed to create two files in each of these folders - index.html (default) and fruitdet.html.

So here is a limited heirarchy view / tree view :

| |_index.html
| |_fruitdet.html
| |_index.html
| |_fruitdet.html


When a non-registered or a user with Role = free tries to access the page (say fruits/ap) we want the index.html file to get displayed. And similarly, when a user with Role = pro tries to access the page fruits/ap we want him/her to view the fruitdet.html page (without changing the URL).

This also implies, that the fruitdet.html is not to be made viewable for non-registered and non pro users.

However, we are having a tough time figuring out how to accomplish the rewrite rules on Netlify.

Some of the example redirects that we tested and failed -
/fruits/??/index.html /fruits/??/fruitdet.html 200! Role=pro

The above did not work - maybe because we used ?? in the rule (we assumed that it would use regex and each ? would translate to a character)

/fruits/* /fruits/:splat/fruitdet.html 200! Role=pro

The above did not work as well, maybe because we were using content after splat (it might also be because fruits/* implies everything after fruits as such, it would also consider fruits/ap/fruitdet.html inclusive of the above rule.

Note: We have not used the rules to restrict free users or visitors to fruitdet.html because we think that rule would be simpler once we know what wildcard to use. And we would use -
/fruits/??/fruitdet.html /login 401! Role=free,visitor

For now, we have pulled down the redirects, and reverted to the earlier site as we are clueless for now on how to proceed.

We would appreciate if you experienced members of the forum could share us some leads if not direct codes.

Stay safe.

Have you tried:

/fruits/:name/* /fruits/:name/fruitdet.html 200! Role=pro
/fruits/:name/* /fruits/:name/index.html 401!

Thank you so very much Hrishikesh for your suggestion. It worked on the site just as expected.