Search code examples
.htaccessdirectory-structure

.htaccess redirect to subfolder depending on domain navigated to


I am setting up two wordpress sites on one shared hosting plan for a client. 123-reg says on the decription that many sites can be hosted on the same server so I thought this would be a simple click of a button thing but clearly not.

I have two sites sitting in 2 separate sub directories; FolkstockFestival and FolkstockArtsFoundation. I also have two domains www.folkstockfestival.com and folkstockartsfoundation.com. I need each domain to go to its corresponding sub directory.

I thought you'd be able to do this with the DNS settings but I haven't found a way to do that so I think .htaccess is the way forward. With mod_rewrites, is there a way to direct the user to the right directory depending on which domain is requested? The .htaccess file would be in the root directory.

I do not want the sub-directory to show on the domain so www.folkstockfestival.com shows as is but directs to the correct site.

Many thanks


Solution

  • Use DNS to make both of your domains pointing on your server, and use this htaccess :

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} www\.folkstockartsfoundation\.com [NC]
    RewriteRule ^(.*)$ /FolkstockArtsFoundation/$1 [L]
    
    RewriteCond %{HTTP_HOST} www\.folkstockfestival\.com [NC]
    RewriteRule ^(.*)$ /FolkstockFestival/$1 [L]