How Do i properly 301 redirect this?

Discussion in 'Apache' started by mberman84, Feb 5, 2008.

  1. #1
    I have a blog, internetbusinessdaily.net, and I have the preferred domain set to without the "www." I want to redirect any instance of the site with www to non-www. This includes internetbusinessdaily.net/index.php. No matter what, I want the final URL to look like:

    internetbusinessdaily.net/*

    *= anything after that doesnt matter.

    Here's what I have in my .htaccess so far:

    ===================================
    # BEGIN WordPress


    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>



    # END WordPress
    =========================================

    How do i do this properly?

    Thanks!!!
     
    mberman84, Feb 5, 2008 IP
  2. buldozerceto

    buldozerceto Active Member

    Messages:
    1,137
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    88
    #2
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.*$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/1$ [R=301,L]
    </IfModule>

    Try with above code.
     
    buldozerceto, Feb 7, 2008 IP
  3. mberman84

    mberman84 Peon

    Messages:
    511
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Will this mess up the URL formatting that is already on the site? It already maps a database driven URL to a cleaner URL. The code you gave me doesnt seem to include some of the rules from the code i posted. can you confirm? thanks!
     
    mberman84, Feb 8, 2008 IP
  4. buldozerceto

    buldozerceto Active Member

    Messages:
    1,137
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    88
    #4
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.*$ [NC]
    RewriteRule ^(.*)$ http://example.com/1$ [R=301,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    </IfModule>

    This is the final code.
     
    buldozerceto, Feb 9, 2008 IP
  5. mberman84

    mberman84 Peon

    Messages:
    511
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #5
    This didnt work. I replaced example.com with my domain...and nothing changed from my old code. Did i do something wrong?
     
    mberman84, Feb 16, 2008 IP
  6. mberman84

    mberman84 Peon

    Messages:
    511
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #6
    is there a reason that previous post code didnt work?
     
    mberman84, Feb 19, 2008 IP
  7. Pixelrage

    Pixelrage Peon

    Messages:
    5,083
    Likes Received:
    128
    Best Answers:
    0
    Trophy Points:
    0
    #7
    it should be:

    redirect 301 /oldsite/oldpage.htm http://www.newsite.com/newpage.htm
    Code (markup):
    never saw it being done that other way before.
     
    Pixelrage, Feb 19, 2008 IP
  8. mberman84

    mberman84 Peon

    Messages:
    511
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #8
    does this forward every instance of site.com to www.site.com?
     
    mberman84, Feb 19, 2008 IP
  9. Pixelrage

    Pixelrage Peon

    Messages:
    5,083
    Likes Received:
    128
    Best Answers:
    0
    Trophy Points:
    0
    #9
    it would forward just that folder. For instance, if you wanted to do one page to one page, it would be:

    redirect 301 http://www.newsite.com/oldpage.htm http://www.newsite.com/newpage.htm
    Code (markup):
     
    Pixelrage, Feb 20, 2008 IP
  10. mberman84

    mberman84 Peon

    Messages:
    511
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I am looking to 301 redirect with htaccess rules. is this the best way?
     
    mberman84, Feb 20, 2008 IP
  11. Pixelrage

    Pixelrage Peon

    Messages:
    5,083
    Likes Received:
    128
    Best Answers:
    0
    Trophy Points:
    0
    #11
    definitely. Also, I'd recommend de-indexing links in your Google Webmaster account (Tools -> Remove URLS) if any of those URLs do not have backlinks.
     
    Pixelrage, Feb 20, 2008 IP
  12. mberman84

    mberman84 Peon

    Messages:
    511
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #12
    but does that rule work in htaccess? does it account for every instance of the domain? i want any URL with WWW to redirect to nonWWW. thanks
     
    mberman84, Feb 20, 2008 IP
  13. mberman84

    mberman84 Peon

    Messages:
    511
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #13
    i still dont have a working solution for this. can someone please help me.

    the code i currently have is at the top of this thread. i need to keep what is there but add the functionality to allow any page with www. to 301 redirect to non-www...regardless of what page it is.

    thanks
     
    mberman84, Feb 26, 2008 IP
  14. kulinar

    kulinar Member

    Messages:
    45
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #14
    If you use wordpress, you should change WordPress address (URL) and Blog address (URL) in Options-> General
     
    kulinar, Feb 26, 2008 IP
  15. mberman84

    mberman84 Peon

    Messages:
    511
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #15
    I already have it the correct way, but that doesnt redirect www. to non-www.
     
    mberman84, Feb 27, 2008 IP
  16. kulinar

    kulinar Member

    Messages:
    45
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #16
    I also use wordpress and no problem with redirect. Watch the URL

    www.trip-tips.com or try this htaccess code
    RewriteEngine On
    RewriteBase /
    [B]RewriteCond %{HTTP_HOST} ^www.yourdomain.com$ [NC]
    RewriteRule ^(.*)$ http://yourdomain.com/1$ [R=301,L][/B]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    Code (markup):
     
    kulinar, Mar 10, 2008 IP