Zeest Posted September 6, 2006 Share Posted September 6, 2006 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.comHeres the situationDNS Settings.............My domain : www.xyz.comA 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 :) Quote Link to comment Share on other sites More sharing options...
oldmanice Posted September 6, 2006 Share Posted September 6, 2006 NameVirtualHost *:80<VirtualHost *:80> DocumentRoot /abc/xyz ServerName xyz.com</VirtualHost>Should beNameVirtualHost <*:80><VirtualHost *:80> DocumentRoot /abc/xyz ServerName xyz.com ServerAnalises www.xyz.com</VirtualHost>Where the stars are fill in your local ip address Quote Link to comment Share on other sites More sharing options...
Zeest Posted September 6, 2006 Author Share Posted September 6, 2006 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? Quote Link to comment Share on other sites More sharing options...
oldmanice Posted September 6, 2006 Share Posted September 6, 2006 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. Quote Link to comment Share on other sites More sharing options...
R_P Posted September 6, 2006 Share Posted September 6, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.