domain pointing to a folder

This approach has you code the first part of the domain or subdomain name and the associated subdirectory in your .htaccess file.   For example:





RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/
subdirectory/
RewriteCond %{HTTP_HOST} ^(www\.)?
name\.
RewriteRule ^(.*)$
subdirectory/$1 [L]

Note the second line has name, NOT name.com.   And note that there are some restrictions when using this method.

  • Domains and subdomains are treated exactly the same.  The pointing is based on the first argument of the url.  In this example name.com (as a pointed domain name) or name.domain.com (as a pointed subdomain) ends up at htdocs/subdirectory.   This is particularly useful in certain situations, for example if you want the subdomains of more than one domain to point to the same place, or if you have both a .com and a .net domain name you want pointed to the same place.
  • You must create a subdirectory under htdocs for every domain and subdomain you wish to be pointed.  The subdirectory name is then coded into the htaccess file.
  • The first argument in the url must be unique.  You cannot have two domains or subdomains with the same name.  sub.domain1.com and sub.domain2.com will both go to the same subdirectory.
  • It defaults to allow www. as a prefix on any domain or subdomain.
  • The root directory with this htaccess file is the “drop through” for any domain or subdomain not found.  You may want to put an error not found page as the default page.  Or, you could choose to have your main website be the “drop through” and just leave that one in the root.

There is also a simplified variation of this method that can be used in less complex situations where you are simply pointing a domain name and want ALL subdomains of that one domain to be pointed to a specific directory.   In this example name.com and any subdomain (including www) of that domain would be pointed to htdocs/subdirectory:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/
subdirectory/
RewriteCond %{HTTP_HOST}
name.com$
RewriteRule ^(.*)$
subdirectory/$1 [L]

In both examples, the htacess code works this way.   The first two lines set up the Apache server rewrite process.   Then you have two RewriteCond statements and a RewriteRule for EACH domain or subdomain you wish to point.





source: http://tips-scripts.com/pointing

This entry was posted in htaccess and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>