I wish to write b .htaccess script that inspections in which a request is originating from and where it really wants to finish up. And with respect to the result maybe do an action.

For instance, I would like all scripts which are run from "/websites//" to pass through a validation. If stated script is attempting to achieve for any file or directory that's not in "/websites//" it'll instantly redirect the request.

Some visual good examples (request => redirect):

"/websites/{identifier}/" => "/websites/{identifier}/"
"/websites/" => "/websites/{identifier}/"
"/websites/{identifier}/script.php" => "/websites/{identifier}/script.php"
"/websites/script.php" => "/websites/{identifier}/script.php"

Will it be achieved? How?