Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: .htaccess / redirect to 'www.'

  1. #11
    jest is offline Newbie Net Builder
    Join Date
    Mar 2009
    Location
    The island across from Eden...
    Posts
    45
    Thanks
    0
    Thanked 2 Times in 2 Posts
    IS there any benefit/effect to using NON www versus redirecting to www version?

  2. #12
    Josh Manders's Avatar
    Josh Manders is offline Web Developer Extraordinaire
    Join Date
    Jul 2009
    Location
    Dubuque, Iowa, USA
    Posts
    63
    Thanks
    3
    Thanked 15 Times in 10 Posts
    Quote Originally Posted by jest View Post
    IS there any benefit/effect to using NON www versus redirecting to www version?
    Mostly a preference thing.

    Here's the code I use:
    Code:
      RewriteEngine On
    
      Options +FollowSymLinks
    
      RewriteBase /
      RewriteCond %{HTTP_HOST} ^([^.]+\.(com|net|org))$ [NC]
      RewriteRule ^(.*)$ http://www.%1/$1 [L,R=301]
    What that does is pretty much uses regex to automatically redirect anysite.com/net/org to www.anysite.com/net/org

  3. #13
    Canonical is offline Unknown Net Builder
    Join Date
    Jul 2009
    Posts
    35
    Thanks
    0
    Thanked 19 Times in 11 Posts
    The problem with the following:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com$
    RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]
    and others that use the !^www pattern variations is that if you ever have additional subdomains other than www that resolve to this address like mail.yourdomain.com or widgets.yourdomain.com then this is going to cause issues. It's much better IMO when redirecting web pages using 301 redirects in Mod_Rewrite to be as specific as you can when creating 'general' redirects (sounds like an oxymoron... I know...)

    IMO the better solution is to ONLY redirect requests for http://yourdomain.com to the www version using something like:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^yourdomain\.com$
    RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]
    This should be placed at the bottom of your .htaccess file in the root folder of your web so that IF the URL qualifies for another redirect, it doesn't get redirected twice. More specific redirects (like those for specific URLs) go near the top... more general redirect (like this one that redirects all non-www to www) go near the bottom.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. .htaccess All Page Redirect
    By ProxySites.ca in forum Managing
    Replies: 7
    Last Post: 28 May, 2010, 22:52 PM
  2. .htaccess
    By dodolls in forum Managing
    Replies: 6
    Last Post: 15 November, 2009, 06:58 AM
  3. .htaccess help needed - dynanmic redirect
    By DomainMagnate in forum Programming
    Replies: 13
    Last Post: 27 September, 2009, 11:52 AM
  4. .htaccess help
    By Sami4u in forum Building
    Replies: 3
    Last Post: 14 September, 2009, 13:47 PM
  5. .htaccess - How to properly redirect a domain?
    By Shenron in forum Programming
    Replies: 10
    Last Post: 9 January, 2009, 08:30 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •