mjlyons Posted November 17, 2006 Posted November 17, 2006 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 Quote
TCH-Bruce Posted November 17, 2006 Posted November 17, 2006 Maybe the article here will help. Basically a 301 redirect without the 301 part: >RewriteEngine on RewriteCond ^yoursite.com [NC] RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L] Quote
TCH-Bruce Posted November 18, 2006 Posted November 18, 2006 Welcome to the forums Mike Sorry I missed that in my first response. Quote
mjlyons Posted November 20, 2006 Author Posted November 20, 2006 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. Quote
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.