Mr. Bungle Posted December 9, 2008 Share Posted December 9, 2008 I'm very new to Linux server administration, so please pardon the beginner question! With regard to DNS records, virtual host config files and the like, specifically how would I redirect all requests made to example.com and www.example.com to subdomain.example.com? Basically, I want subdomain.example.com to be the URL that everyone sees; my domain name is a hack similar to del.icio.us, so I'd want the lazy people who just navigate to icio.us (or even www.icio.us) to be immediately redirected to del.icio.us (interestingly, I just realized that del.icio.us doesn't even do this). My hosting company recommended that I set up two virtual hosts - one for example.com and www.example.com that redirects to the other one, subdomain.example.com. I asked a web developer friend for a second opinion, and he thinks that I can do this purely on the DNS level. Please be as specific as you can, since I'm pretty new. Thanks in advance for any help! Quote Link to comment Share on other sites More sharing options...
trq Posted December 9, 2008 Share Posted December 9, 2008 You couldn't do this on a DNS level. While you could (on a DNS level) have the domains example.com, www.example.com and subdomain.example.com all point at the same server, if a user types example.com into there browser it will stay example.com. Forcing all requests to go to subdomain.example.com however is simple using apache's mod_rewrite module. RewriteEngine on RewriteCond %{HTTP_HOST} !^subdomain\.example\.com [NC] RewriteRule ^/(.*)$ http://subdomain.example.com/$1 [R=301,L] Simply place this rule within a .htaccess file within your document root to enable it. Quote Link to comment Share on other sites More sharing options...
Mr. Bungle Posted December 9, 2008 Author Share Posted December 9, 2008 thorpe, thank you so much! This worked like a charm. I actually inserted your code into my apache2.conf file and then had to enable the mod_rewrite module by following the instructions at http://ubuntuforums.org/archive/index.php/t-7304.html. Again, really appreciate it - problem solved! 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.