If you are sharing one IP address for multiple web sites, it may be necessary for you to setup some redirects. Whatever the reason, here is a sample of a .htaccess file that will do just that. This can also be used in the section of the Apache httpd config file.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} www.mydomain.net
RewriteCond %{REQUEST_URI} !mydomain/
RewriteRule ^(.*)$ mydomain/$1 [L]
RewriteCond %{HTTP_HOST} mydomain.net
RewriteCond %{REQUEST_URI} !mydomain/
RewriteRule ^(.*)$ mydomain/$1 [L]
In this example, there are two domains sharing one IP address for web hosting. The first domain (which isn’t mentioned in the htaccess file is www.mymaindomain.net and the second domain is www.mydomain.net (note – these are obviously fictitious domains). The .htaccess file is located in the root of the mymaindomain.net webroot.
The second domain is located in a subdirectory of the web site for the main domain (e.g., http://www.mymaindomain.net/mydomain). The htaccess file basically rewrites the URL automatically if you request http://www.mydomain.net or http://mydomain.net.
Rewriting URLs is black magic to me. I managed to get the above rules working, but don’t ask me how to do anything more complex! Regular expressions are not my forté.
Oh.. here is another sample.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.net$
RewriteRule ^/(.*) http://www.mydomain.net/$1 [R]
RewriteCond %{HTTP_HOST} ^newsite.mydomain.net$
RewriteRule ^/(.*) http://www.mydomain.net/$1 [R]
RewriteCond %{HTTP_HOST} ^docs.mydomain.net$
RewriteRule ^/(.*) http://www.mydomain.net/index.php?id=docs [R]