Virtual site maps to two different locations

Using a single web hosting account to host multiple sites

Virtual site maps to two different locations

Postby sromanski » Thu Mar 27, 2008 6:18 pm

Is it possible (I would assume it is) to have a site:

www.siteA.com that points all traffic to
/content/siteA/

All traffic would go to the above directory UNLESS...

a request came through that looks like the following
www.siteA.com/ST/[anything]
then it will map to
/template/siteA/
sromanski
 
Posts: 9
Joined: Thu Mar 27, 2008 5:39 pm

Postby richardk » Thu Mar 27, 2008 6:25 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Add missing trailing slashes for /ST URLs.
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/template/siteA%{REQUEST_URI}/ -d
RewriteRule ^ST/.*[^/]$ %{REQUEST_URI}/ [R=301,L]

# Add all other missing trailing slashes.
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/ST(/.*)?$ [NC]
RewriteCond %{DOCUMENT_ROOT}/content/siteA%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

# Rewrite /ST URLs.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^ST/(.+)$ /template/siteA/$1 [QSA,L]

# Rewrite all other URLs.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^(.+)$ /content/siteA/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

did not work :-(

Postby sromanski » Thu Mar 27, 2008 7:05 pm

I probably should have stated that I'm using Helicon ISAPI mod_rewrite for IIS.

It's giving me the following error message:

Unknown expression on line #3: Options +FollowSympLinks

Without that line is it not possible?

Thank you for such a quick response before by the way.
sromanski
 
Posts: 9
Joined: Thu Mar 27, 2008 5:39 pm

Sorry, I didn't realize

Postby sromanski » Thu Mar 27, 2008 7:28 pm

Sorry Richard,

I didn't realize I had to specify index.htm at the end of the domain.

When I use this:
www.example.com
it pulls my index.htm page from
/www/index.htm

However:
www.example.com/index.htm
pulls my index.htm from
/www/content/siteA/index.htm

Is there a way around this?
sromanski
 
Posts: 9
Joined: Thu Mar 27, 2008 5:39 pm

Postby richardk » Fri Mar 28, 2008 11:57 am

Replace ^(.+)$ with ^(.*)$,
Code: Select all
RewriteRule ^ST/.*[^/]$ %{REQUEST_URI}/ [R=301,L]

with
Code: Select all
RewriteRule ^ST(/.*[^/])?$ %{REQUEST_URI}/ [NC,R=301,L]

and
Code: Select all
RewriteRule ^ST/(.+)$ /template/siteA/$1 [QSA,L]

with
Code: Select all
RewriteRule ^ST(/(.*))?$ /template/siteA/$2 [NC,QSA,L]


If example.com is the only domain you have and you don't have any sub domains, you don't need
Code: Select all
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby sromanski » Sun Apr 06, 2008 8:11 pm

Mod god,

That worked well when I put the *'s in... also NC I guess makes it case insensitive... perfect.

I am trying to do this with sub domains. A couple of questions that I just can't get my head around.

Can you make a rule that applies to all sub domains or do you have to specify it for each sub domain. For example... I'd like to remove CFM as the file extension (Cold Fusion).. would I have to specify that for each sub domain?

I also wanted to call a page called page.cfm if a file is not found.
I used the following:
Code: Select all
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?(.*)$ /page.cfm?page=$1 [L]


I am using sub domains and it blew everything up, is that because I didn't specify a sub domain as one of the RewriteCond?

Thanks

Simon
sromanski
 
Posts: 9
Joined: Thu Mar 27, 2008 5:39 pm

Postby richardk » Mon Apr 07, 2008 12:40 pm

Are you talking about sub domains (something.example.com) or domains? You do not have to specify a (sub) domain condition, if you do not it will apply to everything.

I also wanted to call a page called page.cfm if a file is not found.
I used the following:
...
I am using sub domains and it blew everything up, is that because I didn't specify a sub domain as one of the RewriteCond?

Where did you put it exactly? Is it supposed to apply to example.com in the above rewrite? Do those conditions work with the program you are using?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby sromanski » Mon Apr 07, 2008 2:48 pm

Here's my .htaccess file:

Code: Select all
# SITE 1
# Add missing trailing slashes for /ST URLs.
RewriteCond %{HTTP_HOST} ^(site1\.)?simonit\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/ST/template1%{REQUEST_URI}/ -d
RewriteRule ^ST/.*[^/]$ %{REQUEST_URI}/ [NC,R=301,L]
# Add all other missing trailing slashes.
RewriteCond %{HTTP_HOST} ^(site1\.)?simonit\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/ST(/.*)?$ [NC]
RewriteCond %{DOCUMENT_ROOT}/CT/site1%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]
# Rewrite /ST URLs.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(site1\.)?simonit\.com$ [NC]
RewriteRule ^ST/(.*)$ /ST/template1/$1 [NC,QSA,L]
# Rewrite all other URLs
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(site1\.)?simonit\.com$ [NC]
RewriteRule ^(.*)$ /CT/site1/$1 [NC,QSA,L]
# If file is not found
RewriteCond %{HTTP_HOST} ^(site1\.)?simonit\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?(.*)$ /page.cfm?page=$1 [L]

# SITE 2
# Add missing trailing slashes for /ST URLs.
RewriteCond %{HTTP_HOST} ^(site2\.)?simonit\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/ST/template1%{REQUEST_URI}/ -d
RewriteRule ^ST/.*[^/]$ %{REQUEST_URI}/ [NC,R=301,L]
...
...
... same as above except for site2.simonit.com


What I would like is that if a file is not found...

For example:
http://site1.simonit.com/hello

Then it will redirect to:
http://site1.simonit.com/page.cfm?page=hello

These sites are up and running and that prior mod piece you wrote works great.

http://site1.simonit.com/st/leo.jpg (my new son)
pulls the same file as
http://site2.simonit.com/st/leo.jpg
yet they each have their own content
http://site1.simonit.com
http://site2.simonit.com


[/code]
sromanski
 
Posts: 9
Joined: Thu Mar 27, 2008 5:39 pm

Postby richardk » Wed Apr 09, 2008 3:18 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Add missing trailing slashes for /ST URLs.
RewriteCond %{HTTP_HOST} ^(site1|site2)\.simonit\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/ST/template1%{REQUEST_URI}/ -d
RewriteRule ^ST/.*[^/]$ %{REQUEST_URI}/ [NC,R=301,L]

# Add all other missing trailing slashes.
RewriteCond %{HTTP_HOST} ^(site1|site2)\.simonit\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/ST(/.*)?$ [NC]
RewriteCond %{DOCUMENT_ROOT}/CT/%1%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

# Rewrite /ST URLs.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(site1|site2)\.simonit\.com$ [NC]
RewriteRule ^ST/(.*)$ /ST/template1/$1 [NC,QSA,L]

# Catch 404s.
RewriteCond %{HTTP_HOST} ^(site1|site2)\.simonit\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/CT/%1%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}/CT/%1%{REQUEST_URI} !-d
RewriteRule ^(.*)$ /page.cfm?page=$1 [L]

# Rewrite all other URLs that exist.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(site1|site2)\.simonit\.com$ [NC]
RewriteRule ^(.*)$ /CT/site1/$1 [NC,QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby sromanski » Thu Apr 10, 2008 8:35 pm

thank you very much mod god,

worked well... I did end up switching the last section a little and then copying it (there probably a nicer way to do it... but it worked)

Code: Select all
# Rewrite all other URLs that exist.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^site1\.simonit\.com$ [NC]
RewriteRule ^(.*)$ /CT/site1/$1 [NC,QSA,L]

# Rewrite all other URLs that exist.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^site2\.simonit\.com$ [NC]
RewriteRule ^(.*)$ /CT/site2/$1 [NC,QSA,L]


cheers

Simon
sromanski
 
Posts: 9
Joined: Thu Mar 27, 2008 5:39 pm

Next

Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 7 guests

cron