#1
  1. No Profile Picture
    Contributing User
    SEO Chat Discoverer (100 - 499 posts)

    Join Date
    Nov 2006
    Posts
    130
    Rep Power
    17

    Htaccess www to non www


    I hear its a good idea to pick your preferred domain in google webmaster tools and also to redirect one to the other via htaccess such as the example below

    Here is the code you should use if you want people to redirect from WWW to non-WWW:
    (for example, if someone types in http://www.domain.com, it will forward to http://domain.com)

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
    RewriteRule ^.*$ http://domain.com%{REQUEST_URI} [R=301,L]

    In both cases, make sure to replace “domain” with the URL of your domain.

    My question is this, I have a wordpress blog inside a subdirectory. Do I have to do anything different with the root htaccess file or will it just flow through my site.

    Second when it comes to wordpress I have a htaccess file in the and in the blog directory, do i have to enter it in both?

    Thanks
  2. #2
  3. Super Moderator
    SEO Chat Mastermind (5000+ posts)

    Join Date
    Mar 2004
    Location
    Gloucester (South West UK).
    Posts
    6,533
    Rep Power
    3522
    Hi Zoddy,

    First of all, the "normal method" would be to redirect from "non-www" to "www" ('though it's not really important because what you're doing here will create your "standard").

    The following code is much more straightforward:

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

    Here's the same thing for "2-part tld's":

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^domain.co.uk
    RewriteRule (.*) http://www.domain.co.uk/$1 [R=301,L]

    Just select the relevant one and put it in the .htaccess file at your domain root and it will work for the entire domain (including subfolders).
    Last edited by ClickyB; Jun 29th, 2007 at 05:09 AM.
    ClickyB
    "The quality of the visitor is more important than the volume..." (Egol 22nd Feb 2008)
    [New to SEO/SeoChat?] [Canonical Problems?] [Forum Rules & Posting Guidelines]
  4. #3
  5. No Profile Picture
    Contributing User
    SEO Chat Discoverer (100 - 499 posts)

    Join Date
    Nov 2006
    Posts
    130
    Rep Power
    17
    Thanks I will try that out. Is there a way to determine if its actually working?
  6. #4
  7. Super Moderator
    SEO Chat Mastermind (5000+ posts)

    Join Date
    Mar 2004
    Location
    Gloucester (South West UK).
    Posts
    6,533
    Rep Power
    3522
    Originally Posted by zoddy
    Thanks I will try that out. Is there a way to determine if its actually working?
    Yes... and you're gonna kick yourself when you read this

    1. Back up your .htaccess file.
    2. Add the code.
    3. Upload the .htaccess file.
    4. Try to access your domain index with "www".
    5. Try to access your domain index without "www" (you should automatically be forwarded to the same url "with www").
    6. Try to access a url deep inside your domain without "www" (you should automatically be forwarded to the same url - "with www").
    7. If it doesn't work correctly, re-upload the original .htaccess
  8. #5
  9. No Profile Picture
    Contributing User
    SEO Chat Discoverer (100 - 499 posts)

    Join Date
    Nov 2006
    Posts
    130
    Rep Power
    17
    well i tried both versions up top and it kind of works.
    The main page that doesnt have the blog at the root works great. You can type in domain.com and you are redirected to www.domain.com

    However the blog doesnt redirect it either does one of two things depending on which code I use above

    1. I tried it with a deep embedded post and all it does is redirect me to the index page
    2. Or it does nothing at all

    Comments on this post

    • dzine agrees : (0) The code posted above might clash with the code that's already there. WP for example uses .htaccess for some of its basic functions...
  10. #6
  11. rod@missionop.com
    SEO Chat Mastermind (5000+ posts)

    Join Date
    Mar 2003
    Location
    Palm Beach Gardens FL 33410
    Posts
    16,979
    Rep Power
    0
    Eight year old thread doesn't need any new opinions.

Similar Threads

  1. 301 Redirect only in htaccess and not PHP?
    By distinctseo in forum Search Engine Optimization
    Replies: 3
    Last Post: Aug 2nd, 2006, 01:49 AM
  2. How do I edit [my] htaccess for for a 301 redirect
    By sprouter in forum Search Engine Optimization
    Replies: 0
    Last Post: Feb 27th, 2006, 06:41 PM
  3. htaccess - only accessed through include from subdirectories???
    By AndyFX in forum SEO Help (General Chat)
    Replies: 4
    Last Post: Nov 16th, 2005, 08:58 AM
  4. htaccess goes >poof<
    By Robert Paulson in forum SEO Help (General Chat)
    Replies: 3
    Last Post: Mar 19th, 2005, 12:55 PM
  5. Any specific order for htaccess?
    By Adrew in forum Web Design, Coding and Programming
    Replies: 1
    Last Post: Mar 13th, 2005, 06:46 AM

IMN logo majestic logo threadwatch logo seochat tools logo