Welcome to WebmasterWorld Guest from 18.208.187.169

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Domain Mapping Using .htaccess

mapping multiple domains on same account

     
4:27 pm on Feb 21, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 21, 2004
posts:48
votes: 0


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?


RewriteCond %{HTTP_HOST} ^www\.secondary-site\.co\.uk [NC]
RewriteRule (.*) /websites/secondarysite/$1 [L]
12:36 am on Feb 22, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Yes, but you may need to prevent a looping problem:

RewriteCond %{HTTP_HOST} ^(www\.)?secondary-site\.co\.uk [NC]
RewriteCond %{REQUEST_URI} !^/websites/secondary-site/
RewriteRule (.*) /websites/secondary-site/$1 [L]

The other tweak is to accept www- or non-www.

Jim

3:09 pm on Feb 22, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 21, 2004
posts:48
votes: 0


Thanks for that jdmorgan,

I knew I was missing something, not sure if I need the final tweak to accept the www and non-www as I thought I think im forcing the www. version

Full code

RewriteCond %{HTTP_HOST} ^primary-site\.co\.uk [NC]
RewriteRule (.*) [primary-site.co.uk...] [R=301,L]

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

RewriteCond %{HTTP_HOST} ^secondary-site\.co\.uk [NC]
RewriteCond %{REQUEST_URI}!^/websites/
RewriteRule (.*) /websites/$1 [L]

Does this setup look alright?

7:36 pm on Feb 22, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Yes, but I think you're missing the "www\." in the last RewriteCond. Since "www." will be added by the second rule, the third rule won't ever match as it stands now.

Jim

8:50 pm on Mar 2, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 21, 2004
posts:48
votes: 0


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

If I try going to

[primary-site.co.uk...] it works perfectly

However, if I go to [primary-site.co.uk...]

It presents a 302 redirect to [secondary-site.co.uk...]

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

Present Code:

RewriteCond %{HTTP_HOST} ^primary-site\.co\.uk [NC]
RewriteRule (.*) [primary-site.co.uk...] [R=301,L]

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

RewriteCond %{HTTP_HOST} ^www\.secondary-site\.co\.uk [NC]
RewriteCond %{REQUEST_URI}!^/websites/
RewriteRule (.*) /websites/$1 [L]

9:18 pm on Mar 2, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


None of your code does a 302 redirect. So look elsewhere for the code that's doing this. It could be something your host is doing, a domain-forwarding "service", etc.

Jim