Jump to content

[SOLVED] How do I redirect to a subdomain?


Mr. Bungle

Recommended Posts

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

Link to comment
Share on other sites

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.

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.