WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] 404 error - need 301 redirect in htaccess (12 posts)

  1. amberbalanced
    Member
    Posted 3 years ago #

    hi there,

    i have my old site carrieonthecheap.wordpress.com redirected to my new site http://www.blondeandbalanced.com.

    my old site used the permalink format yyyy/mm/dd/link/ but my new site just uses the format /link.

    i'm getting lots of 404 errors in google because of this.

    someone told me i need to do a 301 redirect on every page in my htaccess folder to fix this.

    i have no idea how to do that. anyone have any tips?

    Thanks!!

  2. Shirley! But it's really easy and you can do it in one line.

    You want to put this ABOVE your .htaccess calls to WordPress:

    RewriteRule ^([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ http://www.blondeandbalanced.com/$4 [L,R=301]

    That says 'Any URL starting with ####/##/##/ANYTHING should become /ANYTHING'

    Now. That said, it's a BAD idea to just use /postname in your urls. Read this: http://ottopress.com/2010/category-in-permalinks-considered-harmful/

  3. amberbalanced
    Member
    Posted 3 years ago #

    Awesome!!! You rock.

    Okay ... so I did this, but links are still not being redirected ... will it take awhile?

    So you say it's bad to just have /postname/ ... is an even worse idea to change it this late in the game? i feel like changing it again will be a bad idea! and it just scares me :)

  4. Try

    RewriteRule ^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ http://www.blondeandbalanced.com/$4 [L,R=301]

    And make SURE this is ABOVE the normal WordPress calls :)

    I'd personally just change permalinks back to YYYY/MM/DD/POSTNAME, it'll redirect on it's own.

  5. amberbalanced
    Member
    Posted 3 years ago #

    Hmmm ... it still doesn't seem to be working. Does it take time to work?

  6. Normally no, it's instantaneous. The only times its not is if your host caches the .htaccess file (BAD, but GoDaddy did this for a while and may still) OR if you have your own caching software.

    What's your FULL .htaccess file?

  7. amberbalanced
    Member
    Posted 3 years ago #

    I'm using bluehost...

    RewriteRule ^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ http://www.blondeandbalanced.com/$4 [L,R=301]

    # Use PHP5 Single php.ini as default
    AddHandler application/x-httpd-php5s .php

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

    # END WordPress

  8. Ah. Okay, try this:

    # Use PHP5 Single php.ini as default
    AddHandler application/x-httpd-php5s .php
    
    RewriteEngine On
    RewriteRule ^([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ http://www.blondeandbalanced.com/$4 [L,R=301]
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
  9. amberbalanced
    Member
    Posted 3 years ago #

    you just made my day. thank you thank you soooo much!!!

  10. The reason it worked: I put a call to RewriteEngine On right above the rewrite rule. Some servers need that declaration, others don't. Also, moving the call BELOW the AddHandler ensures you're using PHP 5 :D

    If you have to make any more changes, I would put them in between the rule we added and the #BEGIN WordPress line :)

  11. amberbalanced
    Member
    Posted 3 years ago #

    Awesome!! Thank you so much!! I feel like I learned something new today :)

  12. amberbalanced
    Member
    Posted 3 years ago #

    One more thing ... when I converted to a new/self-hosted blog, I deleted some old posts on my old blog. My google webmasters tool is telling me I'm getting "not found" errors for those links I deleted.

    Is there a way I can redirect all those deleted links to just the homepage of my new blog? Is that the correct way to do it?

    Thanks!!

Topic Closed

This topic has been closed to new replies.

About this Topic