'htaccess check url and reconstruct it on specific condition

Is it possible with .htaccess to check if a URL has a certain path and then reconstruct it?

My issue is that I need to take a URL in this format:

https://example.com/subdirectory/group/test_1

and if the URL matches:

https://example.com/subdirectory/group/

without the hash to reconstruct the URL adding the hash to be:

https://example.com/subdirectory/#/group/test_1

so in essence I would be checking if the URL is:

https://example.com/subdirectory/group/

and if it is changing it to be:

https://example.com/subdirectory/#/group/


Solution 1:[1]

RewriteRule ^subdirectory/(group/.*) /subdirectory/#/$1 [R=302,NE]

That rule should basically do the trick.

R=302 for testing, make that into a 301 once you verified it works properly.

The NE / noescape flag is necessary, so that the # stays a #, and doesn't get escaped to %23.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 CBroe