Virtualhosts need HELP please

Using a single web hosting account to host multiple sites

Virtualhosts need HELP please

Postby TSoft » Wed Sep 30, 2009 8:44 am

Hello,

I created a webhosting. The domain is webtry.org. In the DNS I created a A Record with wildcard (everydns.net) like *.webtry.org and another A Record like www.webtry.org. Both points to the same IP (a dedicated Server with apache server)

I need a rewrite condition and rule to link all subdomain to their home folder... for example:

http://site1.webtry.org must go in /home/site1

http://site2.webtry.org must got in /home/site2


only www.webtry.org have to go in /var/www

Is this possible ?

Thanks all for help and sorry for my english :)
TSoft
 
Posts: 4
Joined: Wed Sep 30, 2009 8:34 am

Postby richardk » Wed Sep 30, 2009 1:20 pm

If you have full access to the server you should not use mod_rewrite.

You would use mod_vhost_alias. Something along the lines of
Code: Select all
# Catch all.
<VirtualHost *:80>
   ServerName          _default_

   DocumentRoot        /var/www
</VirtualHost>

# For webtry.org and www.webtry.org
<VirtualHost *:80>
   ServerName          webtry.org
   ServerAlias         www.webtry.org

   DocumentRoot        /var/www
</VirtualHost>

# For *.webtry.org
<VirtualHost *:80>
   ServerName          a.webtry.org
   ServerAlias         *.webtry.org

   DocumentRoot        /home/
   VirtualDocumentRoot /home/%-3+
</VirtualHost>
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby TSoft » Wed Sep 30, 2009 2:03 pm

Thanks a lot, it works fine :)

Just another question:


it is possible that all subdomains like http://*.domain.com if someone use http://www.*.domain.com to become the same result ?

I try to explain better:

Now site1.domain.com and all others subdomain were redirected to /home/user, that's fine.

But if want that http://www.site1.domain.com do the same ?

I try:

<VirtualHost *>
ServerName *.webtry.org
ServerAlias www.*.webtry.org
DocumentRoot /home/
VirtualDocumentRoot /home/%-3+
ErrorLog /var/log/apache2/error.log
</VirtualHost>

but is seem not to work :-?
TSoft
 
Posts: 4
Joined: Wed Sep 30, 2009 8:34 am

Postby richardk » Wed Sep 30, 2009 5:01 pm

You could redirect to remove the www
Code: Select all
# Catch all.
<VirtualHost *:80>
   ServerName          _default_

   DocumentRoot        /var/www
</VirtualHost>

# For webtry.org and www.webtry.org
<VirtualHost *:80>
   ServerName          webtry.org
   ServerAlias         www.webtry.org

   DocumentRoot        /var/www
</VirtualHost>

# For *.webtry.org
<VirtualHost *:80>
   ServerName          a.webtry.org
   ServerAlias         *.webtry.org

   Options +FollowSymLinks

   RewriteEngine On

   RewriteCond %{HTTP_HOST} ^www\.(.+\.webtry.org)$ [NC]
   RewriteRule ^(/.+)$ http://%1$1 [R=301,L]

   DocumentRoot        /home/
   VirtualDocumentRoot /home/%-3+
</VirtualHost>
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby TSoft » Thu Oct 01, 2009 12:39 am

Unfortunatly it seems not to work :(


It don't remove www :x
TSoft
 
Posts: 4
Joined: Wed Sep 30, 2009 8:34 am

Postby richardk » Thu Oct 01, 2009 8:25 am

Replace
Code: Select all
   RewriteCond %{HTTP_HOST} ^www\.(.+\.webtry.org)$ [NC]
   RewriteRule ^(/.+)$ http://%1$1 [R=301,L]

with
Code: Select all
   RewriteCond %{HTTP_HOST} ^www\.(.+\.webtry\.org)$ [NC]
   RewriteRule ^(/.*)$ http://%1$1 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby TSoft » Thu Oct 01, 2009 8:59 am

It works very GOOD, :D :D :D THANKS's a lot richardk.


I think that it's normal when someone type http://www.user.webtry.org he would be redirected... ?

In the IE Explorer the link appears like http://user.webtry.org


Thank's a lot. And again, sorry for my english :)
TSoft
 
Posts: 4
Joined: Wed Sep 30, 2009 8:34 am


Return to Domain Handling

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

cron