redirect domain after check for alive

Using a single web hosting account to host multiple sites

redirect domain after check for alive

Postby huyhoa » Sat Aug 18, 2007 6:04 am

I have a server at home and have 2 computer make a web server. But when computer 1 (name A) run, i shutdown computer 2 (name 2) and if computer 2 run, i shutdown computer 1.
I use moderm zyxel and when i confix post first i open port 80 for computer 1 and second i open port 81 for computer 2. (Zyxel moderm dont allow to use open 1 port 80 for computer 1 and second computer much use other port like 81).
Now i want to use 3th host and check it, if cant connect to my home ip throught port 80 then it will open it in port 81, and if all 80 and 81 open, it connect to port 80 first.
How can i do that?
Please help me. Thank you very much
huyhoa
 
Posts: 35
Joined: Tue Nov 28, 2006 2:25 am

Postby richardk » Sat Aug 18, 2007 3:18 pm

Now i want to use 3th host and check it, if cant connect to my home ip throught port 80 then it will open it in port 81, and if all 80 and 81 open, it connect to port 80 first.
How can i do that?

If i understand correctly, you can't do that because you have to connect to the requested server (server 1, on port 80) for the mod_rewrite to run. If the server isn't connected, mod_rewrite can't run.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

thank

Postby huyhoa » Sun Aug 19, 2007 8:13 am

hi, thank for your reply but you dont understand what i mean.
I mean, the .htaccess file i will host at other host (in dreamhost) and when go to mydomain.com (host at dreamhost, it will check my server for 2 port that i have post)
Can you please help me.?
huyhoa
 
Posts: 35
Joined: Tue Nov 28, 2006 2:25 am

Postby richardk » Sun Aug 19, 2007 2:52 pm

Try this in a .htaccess file in your document root
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond http://hostname-of-home-server/ -U
RewriteRule ^home-server/?$ http://hostname-of-home-server/ [R,L]

RewriteRule ^home-server/?$ http://hostname-of-home-server:81/ [R,L]

When you go to /home-server it should redirect to port 80 if it's connected, else it will redirect to port 81.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby huyhoa » Sun Sep 02, 2007 10:42 am

thanks rechard, it's work great. now i have a prob, please help me
I have 3 server like www1, www2, www3.domain.com and now i want when go to domain.com it will go to random server 1-3. thanks.
huyhoa
 
Posts: 35
Joined: Tue Nov 28, 2006 2:25 am

Postby richardk » Sun Sep 02, 2007 3:29 pm

If you have access to the httpd.conf file you can use a random RewriteMap.

If not you can do it by the request's time (0-19 seconds to www1, 20-39 to www2 and 40-59 to www3)
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{TIME_SEC} ^[0-1]?[0-9]$
RewriteRule ^(.*)$ http://www1.domain.com/$1 [R,L]

RewriteCond %{TIME_SEC} ^[2-3][0-9]$
RewriteRule ^(.*)$ http://www2.domain.com/$1 [R,L]

RewriteRule ^(.*)$ http://www3.domain.com/$1 [R,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 84 guests

cron