Jump to content

Archived

This topic is now archived and is closed to further replies.

Zeest

Virtual Hosts (www or not)

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Is that supposed to be [b]ServerAlias[/b]?


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?

Share this post


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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.