Is this possible?

Using a single web hosting account to host multiple sites

Is this possible?

Postby nogodoo » Wed Aug 16, 2006 2:58 pm

Multi domain handling with mod_rewrite:

I have the following hosts

www.host1.com
www.host2.com
www.hostN.com

Each of these hosts is mapped to a different area of the application, e.g.

If the host is 'www.host1.com' then it should be redirected to 'www.host1.com/pages/gary'
If the host is 'www.host2.com' then it should be redirected to 'www.host2.com/pages/pete'

Ok, so I created a map, domain2handle.map:

www.host1.com gary
www.host2.com pete

----

RewriteMap domain2handle txt:/opt/apache/domain2handle.map

RewriteMap lowercase int:tolower

RewriteCond %{REQUEST_URI} ^/$

RewriteCond ${lowercase:%{HTTP_HOST}} ^(.+)$

RewriteCond ${domain2handle:%1} ^([A-Za-z0-9]+)$

RewriteRule ^/(.*) /pages/%1 [R]

----

So the above checks the incoming host and redirects to the corresponding area.

Now my question is how do I go about checking that the right host is serving the right pages, e.g. how can I check that 'www.host1.com' isn't serving the 'pete' pages and vice-versa?

Right now it's possible for someone to come in on 'http://www.host1.com/pages/pete' which I want to deny.

I've been racking my brains trying to do this, but I can't figure it out... any help would be greatly appreciated!
nogodoo
 
Posts: 2
Joined: Wed Aug 16, 2006 2:30 pm

Postby richardk » Sat Aug 19, 2006 2:26 pm

I would have thought you'd want this (Apache 2 only though):
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteMap domain2handle txt:/opt/apache/domain2handle.map
RewriteMap lowercase     int:tolower

RewriteCond ${lowercase:%{HTTP_HOST}} ^(.+)$
RewriteCond ${domain2handle:%1} ^([A-Za-z0-9]+)$
RewriteCond %1%{REQUEST_URI} !^([A-Za-z0-9]+)/pages/\1(/.*)?$
RewriteRule .* /pages/%1%{REQUEST_URI} [R=301,L]


It should redirect www.host1.com/abc to www.host1.com/pages/gary/abc and www.host1.com/pages/pete to www.host1.com/pages/gary/pages/pete but not www.host1.com/pages/gary/*.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby nogodoo » Tue Aug 29, 2006 4:32 am

Many thanks... that did the trick.
nogodoo
 
Posts: 2
Joined: Wed Aug 16, 2006 2:30 pm


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 28 guests

cron