Forum Moderators: phranque
I'd like to be able to have:
example1.com
example2.com
example3.com.au
All on the one space which doesn't allow subdomains, etc. I can have aliases which are already set up.
Following jdMorgan's tips from the linked thread above, how would I code the .htaccess for the three domains, each of which will reside in the following folders:
ex1
ex2
ex3
TIA
I should point out that it's usually better to use the standard VirtualHost definition method in httpd.conf or other server-config files instead of using mod_rewrite. Doing so has many advantages related to security and site and server administration. I can't recommend using the mod_rewrite approach unless you simply have no other choice.
Jim
Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^(www\.)?example1\.com [OR]
RewriteCond %{HTTP_HOST} ^$
RewriteCond $1!^ex1/
RewriteRule (.*) /ex1/$1 [L]
#
RewriteCond %{HTTP_HOST} ^(www\.)?example2\.com
RewriteCond $1!^ex2/
RewriteRule (.*) /ex2/$1 [L]
#
RewriteCond %{HTTP_HOST} ^(www\.)?example3\.com\.au
RewriteCond $1!^ex3/
RewriteRule (.*) /ex3/$1 [L]
I don't think I have access to httpd.conf and would now have to wait until Monday to find out for sure in any case.
However, you could save some code and eliminate maintenance by using the domain name (or the domain name plus TLD) prefixed with a few 'tag' characters (for loop-stopping) as the subdirectory name:
Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.com [OR]
RewriteCond %{HTTP_HOST}>example1 ^(>)(.+)$
RewriteCond $1 !h_
RewriteRule ^(.*)$ /h_%2/$1 [L]
I'd suggest that you add a 301-redirect rule above this one to force canonicalization of all domain names to either "www" or "non-www" both for SEO/duplicate-content-prevention reasons, and so that you don't have to allow for the "www" being optional in all subsequent rules. For example, if you canonicalize to "www" the preceding code simplifies to:
Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.com [OR]
RewriteCond %{HTTP_HOST}>example1 ^>(.+)$
RewriteCond $1 !h_
RewriteRule ^(.*)$ /h_%1/$1 [L]
Jim
I've used example1.com, example2.com, etc in this example because in previous threads I have read you admonishing people for using actual domains and told them to use 'example.com'
My understanding of your sample code would be that it literally works for three domains with a numeral at the end. How would it work for:
bob.com
jane.org
spot.com.au
?
I have further questions re your sample code, but they are dependant on your reply to this question.
Thanks,
Bruce