.htaccess tutorial

htaccess Elite


Multple domains using htaccess

Ask your mod_rewrite and Redirection questions here, and get answers!

Multple domains using htaccess

Postby ti89 » 28 Oct 2006 07:45

Hi,

I know this can be done in http.conf but is it possible to use .htaccess & Mod_rewrite to map domain names to a directory so that you can run multiple independant sites from the same hosting account?

Is the following code along the right lines?

Code: Select all
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule (.*) /sites/example.com/public_html/$1 [L]
ti89
 
Posts: 44
Joined: 28 Oct 2006 07:37

Postby ti89 » 30 Oct 2006 07:57

Just realised this still doesn't work quite properly but can't figure out why.

If I try going to

http://www.primary-site.co.uk/foo/index.html it works perfectly

However, if I go to http://www.primary-site.co.uk/foo/

It presents a 302 redirect to http://www.secondary-site.co.uk/foo/index.html

Can anyone point me in the right direction to find out why? Any help greatly appreciated!

Present Code:
Code: Select all
RewriteCond %{HTTP_HOST} ^primary-site\.co\.uk [NC]
RewriteRule (.*) http://www.primary-site.co.uk/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^secondry-site\.co\.uk [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)?additional-url\.co\.uk [NC]
RewriteRule (.*) http://www.secondary-site.co.uk/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.secondary-site\.co\.uk [NC]
RewriteCond %{REQUEST_URI}!^/websites/
RewriteRule (.*) /websites/$1 [L]
ti89
 
Posts: 44
Joined: 28 Oct 2006 07:37


Return to Redirect or Rewrite Questions