Page 1 of 18 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ... LastLast
Results 1 to 15 of 267
Like Tree3Likes

[How to] Setup www.yourdomain.com or yourdomain.com (www vs. non-www) - With .htaccess 301 redirects

This is a discussion on [How to] Setup www.yourdomain.com or yourdomain.com (www vs. non-www) - With .htaccess 301 redirects within the General Discussion forums, part of the vBSEO SEO Plugin category; Most websites are setup to allow access via either www or non-www. Example: Code: vbseo .com or Code: www. vbseo ...

  1. #1
    Senior Member
    Real Name
    Joseph Ward
    Join Date
    Jun 2005
    Posts
    23,847
    Liked
    32 times
    Blog Entries
    9

    Arrow [How to] Setup www.yourdomain.com or yourdomain.com (www vs. non-www) - With .htaccess 301 redirects

    Most websites are setup to allow access via either www or non-www. Example:

    Code:
    vbseo.com
    or

    Code:
    www.vbseo.com
    However - this can lead to duplication of your content or redundant URLs within the search engines.

    For best SEO, you need to choose one version or the other, to ensure full link consistency and consensus, and to maximum crawling efficiency.

    There are 2 methods of specify which version to use. One is by using your .htaccess file. The second way is to select your preferred format within Google Webmaster Tools.

    Choosing to Use the WWW version of your domain ONLY

    Edit your .htaccess file.
    At the top, add the following new lines:
    Code:
    RewriteCond %{HTTP_HOST} !^www\.example\.com$
    RewriteRule (.*) http://www.example.com/$1 [R=301,L]
    Note: You must replace example.com with your own site URL.

    Once your new .htaccess file is uploaded to the server, your site will ONLY be accessible via the WWW version of your domain.

    Anytime a user or search engine tries to access the non-WWW version of your site, they will be automatically forwarded to the WWW version.

    Choosing to Use the NON-WWW version of your domain ONLY

    • Edit your .htaccess file.
    • At the top, add the following new lines:

    Code:
    RewriteCond %{HTTP_HOST} !^example\.com$
    RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
    Note: You must replace example.com with your own site URL.

    Once your new .htaccess file is uploaded to the server, your site will ONLY be accessible via the NON-WWW version of your domain.

    Any time a user or search engine tries to access the WWW version of your site, they will be automatically forwarded to the NON-WWW version.


    Making Exceptions

    As this will only allow 1 way in, some times an exception must be made for other subdomains. If you need to allow an exception (ie, for a CDN), you can use an 'or' statement, you can do so by replacing

    www:

    Code:
    RewriteCond %{HTTP_HOST} !^www\.example\.com$
    with
    Code:
    RewriteCond %{HTTP_HOST} !(^www\.example\.com$|^cdn\.example\.com$)
    non-www:
    Code:
    RewriteCond %{HTTP_HOST} !^example\.com$
    with
    Code:
    RewriteCond %{HTTP_HOST} !(^example\.com$|^cdn\.example\.com$)
    where | denotes the 'or' case.

    Your CDN subdomain should be blocked via robots.txt at the CDN level. You cannot add it to your local robots file.


    Choosing WWW or NON-WWW version of your domain in Google Webmaster Tools

    If you are not yet using Google Webmaster Tools, you should be. It provides a wealth of info on how to improve your site for SEO purposes.

    Here is a primer on some of the key aspects you should be evaluating with your account:
    Google Webmaster Tools - Recommended for All vBSEO Customers

    To specify which version of your domain to use, login to your account and go to the following section:

    Go to Dashboard > Tools > Set preferred domain

    Associate a preferred domain with this site, to always or never show the leading "www." in Google's search results.

    Google will then ONLY list the WWW or NON-WWW version of your URLs in the index, whichever you select.


    Lighttpd Webserver

    Choosing to Use the WWW version of your domain ONLY

    Please add the following rule to your lighttpd.conf file. In order to edit lighttpd.conf you can use the following command.

    Code:
    # vi /etc/lighttpd/lighttpd.conf
    After editing lighttpd.conf using the vi editor, please save it and restart lighttpd.

    Code:
    $HTTP["host"] =~ "^domain\.com$" { url.redirect = ( "^/(.*)" => "http://www.domain.com/$1" ) }
    You can restart lighttpd with the following commands.

    Code:
    # service lighttpd restart
    # /etc/init.d/lighttpd restart
    Note: You must replace domain.com with your own site URL.

    Choosing to Use the NON-WWW version of your domain ONLY

    Please add the following rule to your lighttpd.conf file. In order to edit lighttpd.conf you can use the following command.

    Code:
    # vi /etc/lighttpd/lighttpd.conf
    After editing lighttpd.conf via the vi editor, please save your lighttpd.conf and restart lighttpd.

    Code:
    $HTTP["host"] =~ "^www\.(.*)" { url.redirect = ( "^/(.*)" => "http://%1/$1" ) }
    You can restart lighttpd with the following commands.

    Code:
    # service lighttpd restart
    # /etc/init.d/lighttpd restart
    Note: You must replace domain.com with your own site URL.
    Last edited by Brian Cummiskey; 12-20-2010 at 06:41 PM. Reason: added or cases

  2. #2
    Senior Member
    Real Name
    .
    Join Date
    Jul 2006
    Posts
    386
    Liked
    3 times
    Blog Entries
    1
    Thanks, I could have used this about a year ago when I first set this up on my sites lol. I'm sure this will be helpful for many users though!

  3. #3
    Senior Member
    Real Name
    Joseph Ward
    Join Date
    Jun 2005
    Posts
    23,847
    Liked
    32 times
    Blog Entries
    9
    Good point Justin. We'll try to do a better job of getting common questions clearly documented on the site.

  4. #4
    Senior Member briansol's Avatar
    Real Name
    Brian
    Join Date
    Apr 2006
    Location
    Central CT, USA
    Posts
    6,981
    Liked
    8 times

  5. #5
    Senior Member
    Real Name
    Joseph Ward
    Join Date
    Jun 2005
    Posts
    23,847
    Liked
    32 times
    Blog Entries
    9



  6. #6
    Member
    Real Name
    usekes
    Join Date
    Aug 2006
    Posts
    79
    Liked
    0 times
    I guess it is not a good idea for active forums, because all of my pages indexed with www. so if i drop www. it means my index will be decrease than google have to reindex new pages without www

  7. #7
    Senior Member briansol's Avatar
    Real Name
    Brian
    Join Date
    Apr 2006
    Location
    Central CT, USA
    Posts
    6,981
    Liked
    8 times
    the htaccess rule 301's it. you shouldn't lose any ranking.

    Plus, in the google webmasters portal, you can set www vs non-www right there. so even if all your links are www in there, you can have them send to non-www.

  8. #8
    Senior Member
    Real Name
    Joseph Ward
    Join Date
    Jun 2005
    Posts
    23,847
    Liked
    32 times
    Blog Entries
    9
    If you already have www indexed, and you are ok with that, I think you are very safe to stick with it.

    We use www here and we won't be changing, even though a few of my own private sites are setup without it.

    One thing we have to consider is "user behavior". It's quite common when someone types in a domain (from memory) that they may include the www part since it's been used so prominently from the early beginnings of the Web.

  9. #9
    Senior Member briansol's Avatar
    Real Name
    Brian
    Join Date
    Apr 2006
    Location
    Central CT, USA
    Posts
    6,981
    Liked
    8 times
    or, they type 'site' and hit ctrl + enter, which auto adds http and www and .com to it

  10. #10
    Senior Member
    Real Name
    Joseph Ward
    Join Date
    Jun 2005
    Posts
    23,847
    Liked
    32 times
    Blog Entries
    9
    Interesting. Good point.

    One thing that has always bothered me is sites that allow one or the other, but do NOT redirect the non-preferred version.

    I have seen major websites (even recently) that give a 404 error if you enter the domain without the www. part.

  11. #11
    Senior Member briansol's Avatar
    Real Name
    Brian
    Join Date
    Apr 2006
    Location
    Central CT, USA
    Posts
    6,981
    Liked
    8 times
    that's because IIS sucks

    oh, wait... i didn't mean to say thaty out loud

  12. #12
    Senior Member
    Real Name
    .
    Join Date
    Jul 2006
    Posts
    386
    Liked
    3 times
    Blog Entries
    1
    Quote Originally Posted by Joe Ward View Post
    Good point Justin. We'll try to do a better job of getting common questions clearly documented on the site.
    Sorry, didn't mean for it to sound like I was complaining :P You guys do a great job with presenting useful information here.

  13. #13
    Senior Member
    Real Name
    Joseph Ward
    Join Date
    Jun 2005
    Posts
    23,847
    Liked
    32 times
    Blog Entries
    9
    Quote Originally Posted by jbartle View Post
    Sorry, didn't mean for it to sound like I was complaining :P You guys do a great job with presenting useful information here.
    I knew you were not complaining. But - we still have not organized all the information will have available to the level that it should be yet. We're working on it.

  14. #14
    Member
    Real Name
    Eric Frost
    Join Date
    Jul 2006
    Location
    LinkBliss
    Posts
    94
    Liked
    0 times
    Thanks, I did it on all my sites.. I had set the Google preferred domain, but did not have the code in .htaccess

  15. #15
    AWS
    AWS is offline
    Member AWS's Avatar
    Real Name
    Bob
    Join Date
    Feb 2006
    Location
    Pluto
    Posts
    68
    Liked
    0 times
    Just posting to make that annoying message go away at the top of the page.

Page 1 of 18 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ... LastLast

Similar Threads

  1. Urgent help with htaccess and 301 redirects
    By markbolyard in forum URL Rewrite Settings
    Replies: 4
    Last Post: 12-02-2007, 05:24 PM
  2. htaccess redirects when moving folder
    By I, Brian in forum Troubleshooting
    Replies: 3
    Last Post: 10-05-2007, 02:47 PM
  3. Help with initial htaccess setup
    By mhc1576 in forum URL Rewrite Settings
    Replies: 1
    Last Post: 12-28-2006, 07:44 AM
  4. Replies: 6
    Last Post: 10-23-2005, 01:32 PM

Posting Permissions

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