Support » Fixing WordPress » 404 error – need 301 redirect in htaccess

  • Resolved amberbalanced

    (@amberbalanced)


    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!!

Viewing 11 replies - 1 through 11 (of 11 total)
  • 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/

    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 🙂

    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.

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

    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?

    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

    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

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

    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 😀

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

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

    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!!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘404 error – need 301 redirect in htaccess’ is closed to new replies.