logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: VirtualHost working for www.site.com, but not site.com
Author
NVergunst



Joined: 29 Nov 2011
Posts: 2

PostPosted: Tue 29 Nov '11 22:10    Post subject: VirtualHost working for www.site.com, but not site.com Reply with quote

I have multiple virtual hosts setup, and when I go to www.site1.com or www.site2.com, it works. However if I go to site2.com, it serves the default first virtualhost which just happens to be for site1.

Is there a way to make www.whatever.com and whatever.com equivalent in the virtualhost?
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3091
Location: Hilversum, NL, EU

PostPosted: Tue 29 Nov '11 22:34    Post subject: Reply with quote

I have this in the virtual host apachelounge:

A Server Alias:
Code:
ServerName www.apachelounge.com
ServerAlias apachelounge.com


When http://apachelounge.com is typed then it gives http://www.apachelounge.com :
Code:
RewriteEngine on
RewriteCond %{HTTP_HOST}   !^www\.apachelounge\.com [NC]
RewriteCond %{HTTP_HOST}   !=""
RewriteRule ^/(.*)         http://www\.apachelounge\.com/$1 [L,R=301]



Steffen
Back to top
NVergunst



Joined: 29 Nov 2011
Posts: 2

PostPosted: Tue 29 Nov '11 22:41    Post subject: Reply with quote

Perfect!

Many thanks.

I added the "ServerAlias" line in the virtualhost config area and it works like a charm.

It looks like the code you posted after that actually makes the URL blah.com into www.blah.com?

It seems like I need the mod_rewrite.so for that, and then put that somewhere like in the main config file? Obviously changing your domain to mine...
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3091
Location: Hilversum, NL, EU

PostPosted: Tue 29 Nov '11 22:50    Post subject: Reply with quote

Yep mod_rewrite.so must be enabled.
Then, just put that code within a virtual host block.

Btw, it is advised to place as first a Default Virtual host, like:
Code:
<VirtualHost *>
    ServerName father (Computer name)
    ServerAlias localhost
    ServerAlias 127.0.0.1
    ServerAlias 85.223.52.177 (your external IP)
    DocumentRoot f:/web/unknown (what ever)
</VirtualHost>

The first VirtualHost section is used for all requests that do notmatch a ServerName or ServerAlias in any <VirtualHost> block.


Steffen
Back to top


Reply to topic   Topic: VirtualHost working for www.site.com, but not site.com View previous topic :: View next topic
Post new topic   Forum Index -> Apache