# what's the real meaning of httpd virtualhost?

## honeymak

hi guys,

i have 2 scenarios

1st:

1 IP, 1 httpd server config file with NO virtualhost sections, several domain names pointing to it

2nd:

1 IP, 1 httpd server config file with virtualhost sections, several domain names pointing to it

what's the real difference for this?

they are both serving those domain names

any "context" problem for programs/apps?

 :Embarassed: 

----------

## malern

Virtualhosting allows you to host many different websites using a single httpd server. I assume you're using apache, which will allow you to define a number of different virtual hosted web sites, and then map certain IP addresses, ports or domain names to each one.

If you only have one website, and want all your domains to point it, then you don't need virtual hosting.

If you enable virtual hosting anyway then it won't do any harm. By default everything will map to a single virtual host. So it'll still work the same, it'll just add a tiny bit more overhead.

----------

## honeymak

then if i have the following case...........

forum.myhost.com -> IP A.B.C.D

www.myhost.com -> IP A.B.C.D

i don't make any virtualhost section in httpd.conf

instead i make rewrite rules

RewriteCond %{HTTP_HOST} ^(forum.myhost.com)$

#hope to internal redirect to www.myhost.com/forum$1 or forum.myhost.com/forum$1

RewriteRule ^(.*)$ /forum$1 [R=permanent,L]

is this possible?

and

how is this different from virtualhost?

 :Embarassed: 

----------

## honeymak

i found that maybe the version of apache has some problem with mod_rewrite......

tried another version and that.......WORKS...as expected....

will check later

 :Wink: 

----------

## malern

 *honeymak wrote:*   

> i don't make any virtualhost section in httpd.conf
> 
> instead i make rewrite rules
> 
> RewriteCond %{HTTP_HOST} ^(forum.myhost.com)$
> ...

 

Yes, you should be able to do an internal redirect so that your forum.myhost.com domain directly accesses your forum

 *honeymak wrote:*   

> how is this different from virtualhost?

 

The end result (i.e. what the user sees) should be the same as if you made a virtualhost for your forum.myhost.com domain and set the DocumentRoot to your forum dir. So use whichever method you find easiest, it should work out the same.

The advantage of virtualhost is that you can set a lot more than just the DocumentRoot. Almost all apache directives can be set for each individual virtualhost. For example, you could set a TimeOut of 30 seconds for www.myhost.com and a TimeOut of 42 seconds for forum.myhost.com. I can't think of a reason why you'd want to do that  :Smile:  but the point is that virtualhosts give you that option.

If you don't need that functionality, then I'd recommend sticking with your redirect if you already have it working.

----------

## Mad Merlin

 *honeymak wrote:*   

> then if i have the following case...........
> 
> forum.myhost.com -> IP A.B.C.D
> 
> www.myhost.com -> IP A.B.C.D
> ...

 

They're different because in your scenario, your users will see the redirect and they'll ultimately end up seeing a longer URL. With virtualhosts, you visit forum.myhost.com and that's it, there's no redirect necessary. Also, using the rewrite method, everything gets munged together into the same directory, so you could get the same content from multiple addresses, such as forum.myhost.com/forum, myhost.com/forum, and completelyunrelated.com/forum, which may be undesirable. The rewrite method is also a lot more complicated.

----------

