Apache configuration has a Directory directive. It is used like a .htaccess file to control access to said directory.
An example:
Order deny,allow
Deny from all
Allow from my.domain.com
The important bit here is the Order statement. Rules will be processed from right to left (in this case all of the deny rules then all of the allow rules. The LAST rule that is matched will the the rule that is used. We are denying everyone and allowing wo we specify.
If you were to specify allow,deny you will be allowing everyone and denying who you specify.
This is quite a complicated system and some personal experimentation should help you understand.
Sometimes you want to redirect the user to a new page based on a specific query string value. Heres  how to do that:
RewriteCond %{QUERY_STRING} foo=bar&bim=bam
RewriteRule ^horrible.php$ /farbetter.html? [R=302]
This redirects all traffic going to “horrible.php?foo=bar&bim=bam” to goto “farbetter.html”. Note that for all other querystring vars horrible.php is still available.
Multiple domains pointing to a single site? Want to divert the traffic based on domain name? Then this is the simple two liner to do it without faffing with virtualhosts.
RewriteCond %{HTTP_HOST} ^(www\.)?mywebsite.com$
RewriteRule   ^/$  /mywebsite.html [L]
RewriteCond %{HTTP_HOST} ^(www\.)?myotherwebsite.com$
RewriteRule ^/$ /myotherwebsite.html [L]
Â

I recently had the need to setup part of a website so that the user needed to agree to terms before accessing. I was not happy about having to make the pages dynamic or use javascript. So instead, this rather elegant apache solution does the job.
Â
This example is based on a three page system, obviously an be made far more flexible than this.
The page “mustagreetoview.html” can only be viewed if the user has agreed to the terms – indicated by the presence of the ‘hasgreed’ cookie. If the cookie ‘hasagreed’ is not set the user is directed to the terms page “pleaseagree.html”. This simply explains to the user that they need to agree to the terms before continuing. The agree link takes the user to “useragress.html”. When this page is requested the “hasagreed” cookie is set by apache.
RewriteRule ^.*useragrees.html$ - [co=hasagreed:YES:.%{SERVER_NAME}]
RewriteCond %{HTTP_COOKIE} !^.*hasagreed.*$ [NC]
RewriteRule ^.*mustagreetoview.html$ /pleaseagree.html [R]