Jump to content

Recommended Posts

Posted

I was wondering if anyone knew how to make any requests to my root domain (example.com) forward to the "www" subdomain (www.example.com).

 

Right now, both the root and www subdomain work fine, but I would prefer everyone to get pushed onto "www" (for port 80 only). I looked into using RedirectMatch in my .htaccess file, but it doesn't seem to have any concept of the domain/subdomain used to get to the server. This just causes an infinite redirect loop :).

 

I looked into DNS, but as far as I can tell, this would redirect all traffic, not just port 80.

 

You might want to take any assumptions I have made with a grain of salt too. I could be totally wrong.

 

Any ideas?

 

Cheers,

Mike

Posted

Hi all,

 

Just tried out your suggestion and I found that while Bruce's code snippet didn't seem to have an effect, the code on the page he linked to did. Here's what worked for me:

 

>RewriteEngine on 
RewriteCond %{HTTP_HOST} ^yoursite.com [NC] 
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]

 

I have no idea why one works and the other doesn't, but the %{HTTP_HOST} and R=301 are both needed (I tried just using one or the other and got some errors).

 

Thanks for your help - it's working great now.

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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