RewriteEngine On
RewriteOptions inherit

RewriteCond %{QUERY_STRING} target=(set|send)
RewriteCond %{ENV:ADEI_SECURITY} .+
RewriteCond %{ENV:ADEI_CONTROL} ^$
RewriteCond %{ENV:ADEI_USERAUTH} ^$
RewriteRule control.php$ - [F]

RewriteCond %{REQUEST_FILENAME} !service.php$
RewriteCond %{REQUEST_URI} ^(.*services/)[\w\d_]+(\.php)?$
RewriteRule ^([\w\d_]+)(\.php)?$  %1service.php?service=$1 [QSA,E=ADEI_REDIRECT:1]

RewriteCond %{QUERY_STRING} service=control
RewriteCond %{QUERY_STRING} target=(set|send)
RewriteCond %{ENV:ADEI_REDIRECT} ^$
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule service.php$ - [F]

<Files  "control.php">
    Order deny,allow
    Deny from all
    Allow from env=!ADEI_SECURITY
    Allow from env=!ADEI_USERAUTH
    Allow from env=ADEI_CONTROL
</Files>
