Jump to content


Photo

Virtual Hosts (www or not)


  • Please log in to reply
4 replies to this topic

#1 Zeest

Zeest
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 06 September 2006 - 12:41 PM

Well I'm very new to Apache configuration. Now I'm in a real tiff right now, where my site can be accessed through something.com but not through www.something.com

Heres the situation

DNS Settings.............
My domain : www.xyz.com
A record for host "xyz.com" points to my box.
and "www.xyz.com" is an alias (CNAME) for host "xyz.com"

httpd.conf settings.......

NameVirtualHost *:80
<VirtualHost *:80>
    DocumentRoot /abc/xyz
    ServerName xyz.com
</VirtualHost>

Now this works just fine when I enter URL as xyz.com but it doesn't work for url www.xyz.com, that takes me to root directory of server.

How to fix this issue?

Also even better would be to just redirect all users entering domain www.xyz.com to xyz.com. Along with the URL changing in the address bar of the browser. So for example if I enter www.xyz.com in browser it should automatically take me to xyz.com along with url changing in browser. I know it can be done but dont know how.

Thankyou for any help :)

#2 oldmanice

oldmanice
  • Members
  • PipPipPip
  • Advanced Member
  • 134 posts
  • LocationIn Your Garden At Night

Posted 06 September 2006 - 03:12 PM

NameVirtualHost *:80
<VirtualHost *:80>
    DocumentRoot /abc/xyz
    ServerName xyz.com
</VirtualHost>

Should be

NameVirtualHost <*:80>
<VirtualHost *:80>
    DocumentRoot /abc/xyz
    ServerName xyz.com
    ServerAnalises www.xyz.com
</VirtualHost>

Where the stars are fill in your local ip address
Join my Froums www.phpbbplanet.com/darkwinter

#3 Zeest

Zeest
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 06 September 2006 - 03:43 PM

Is that supposed to be ServerAlias?


Also what should I do so that users are automatically redirected to xyz.com when they use www.xyz.com? Can it be done using apache or should I use php instead?

#4 oldmanice

oldmanice
  • Members
  • PipPipPip
  • Advanced Member
  • 134 posts
  • LocationIn Your Garden At Night

Posted 06 September 2006 - 09:23 PM

To forward a site to another site you need to see if your domian provider aloows it. If they do then frame it where you can keep the same url in the address bar.
Join my Froums www.phpbbplanet.com/darkwinter

#5 R_P

R_P
  • Members
  • PipPipPip
  • Advanced Member
  • 98 posts

Posted 06 September 2006 - 10:27 PM

oldmanice nearly had it, would look something like this:


<VirtualHost *:80>
	ServerName xyz.com
        ServerAlias xyz.com *.xyz.com
	DocumentRoot /root/etc/xyz

        # Redirect all traffic for this VH to www.

	RewriteEngine on
        RewriteCond %{HTTP_HOST} !^www\.
	RewriteRule .* http://www%{HTTP_HOST}/$1
</VirtualHost>


Having the wildcard (*) in the alias will redirect ALL subdomains of xyz.com to this virtual host, and is a thorough way to redirect traffic. I don't know if that rewrite works, but thats how it would look  8). Wildteen is the guru there and will prolly correct me. Also make sure you uncomment the NameVirtualHost directive.

Good Luck.
Pro in: Win2K3S | Apache2 | PHP5 | Perl5 | MySQL | MSSQL | Firefox | Photoshop
Student of: Ubuntu6 | Java | C | VB.NET | ASP.NET
Developer: Roddzilla Webstudios, Burrson CG, DVIDSHUB, The Four Nations
Student: Georgia Tech, Georgia Tech College of Computing




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users