Jump to content

Virtual Hosts (www or not)


Zeest

Recommended Posts

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?

[b]Also even better would be to just redirect all users entering domain www.xyz.com to xyz.com[/b]. 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 :)
Link to comment
Share on other sites

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
Link to comment
Share on other sites

oldmanice nearly had it, would look something like this:

[code]

<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>

[/code]

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.