How to put a permanent redirect in your htaccess file

Ok, this is going to be a techie post, so beware, but I always find it helpful when I’m searching for solutions to problems to read about how others have solved similar ones.

My permalinks broke over the weekend. I still don’t know why, but they just stopped working in the configuration /archives/%postname%/ as I have had them set up for a LONG time. I searched and searched for a solution to no avail, and finally decided that the only answer was to put a permanent 301 redirect into my .htaccess file. This file is like an instruction manual for all the browsers that visit the site. It tells them what they can and can not do. I downloaded two plugins (Permalink Migration and Permalink Redirect) that were supposed to do this manually, and while I’m sure they will work for many people, neither of them worked for me, for some unknown reason.

So, what to do next? I decided to try just putting one redirect into my htaccess file to see if it would work, and sure enough, it did. The plugins just weren’t able to write to the htaccess file it seems (and yes, I had my permissions set correctly, so that wasn’t the problem). Since the one redirect worked just fine, I’m working my way through my entrance page stats over the last couple of months, to find the majority of ways that people are coming through the “side door” to the site and setting up a redirect for each one. Then I will go back through all 82 posts and get the rest as I have time over the next couple of days. (Anyone have a magic quickie solution that will just spit out a list for me that I can paste into the file?)

How to put a redirect into your htaccess file

It’s fairly simple, just download your .htaccess file from your root directory, and open it with Notepad. At the bottom of the file add the following (replacing my URLs with yours of course):

redirect 301 /archives/a-rainbow-of-free-round-rss-icons http://randaclay.com/freebies/a-rainbow-of-free-round-rss-icons/

What happens if you goof up the code and enter a redirect that doesn’t go anywhere? You’ll bring your entire site down. I did this and began getting Internal Server Errors on every site I have. Not a big deal to fix, but it took me an hour, and a phone call to my host to figure out that I had caused the problem in the first place.

The upside of this is that I’m moving to a better permalink structure, exchanging the empty word “archives” for the more search engine friendly category title.

Anyway, I hope that helps someone else down the line. Now back to our regularly scheduled programming…

[Post to Twitter]  [Post to Delicious]  [Post to Digg]  [Post to StumbleUpon] 

You might also enjoy:

10 Responses

  1. Paul says:

    Thank you for the tip :) You’ve inspired me to bring my .htaccess file up to speed.

  2. eve says:

    Thanks for that, I will be needing that soon!

  3. Mommy Zabs says:

    This is what I have in my .htaccess folder (only i took my info out) and someone had given to me to set my permalinks up right. I’m on K2 for both of my blogs and have had to do this with each to avoid errors.
    ———————–
    # BEGIN WordPress

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

    # END WordPress

    RedirectMatch 301 /200(4|5|6|7)/.*/.*/(.*)/ http://yoursiteurl/$2/
    RedirectMatch 301 /200(4|5|6|7)/.*/(.*)\.html http://yoursiteurl/$2/
    ——————————
    I didn’t have to go through individual posts at all.

    -by the way I found you through writing thoughts, my china site and your site were both linked there. I love the look of your blog, i think we have the same font tastes :)

    Mommy Zabs

  4. Mommy Zabs says:

    i just realized you don’t need the last 2 lines of that code- i had those for another reason. I just fixed my new blog based on the above code in my file teamed with setting my permalinks in the options file to date and named based.
    i hope that saves you some time!

  5. Randa says:

    @MommyZabs – thank you for that. I have had problems with my permalinks the whole time I’ve had this blog. I wonder if that would have solved it. I love the look of your site by the way…. going over to read through it.

  6. Mommy Zabs says:

    I’m very flattered you like my site! :) Not sure if you went to my China one or mommy one :) I learned the .htaccess thing from mamablogga.com. She always publishes good tips. It’s geared toward mommy bloggers but the tips apply toward everyone.

  7. Chris says:

    Glad to see you figured out your issue. Be careful with wordpress because it also likes to overwrite your .htaccess file occasionally when you won’t expect it. Like on a plugin install or a configuration change.

    Just keep a backup of your newly updated file, so you can change it back in a flash :)

  8. Randa Clay says:

    @Chris- thanks for that warning, I appreciate it. I do have a backup copy- after I did a redirect for every stinkin’ post, I definitely made sure a copy stayed here on my PC.

  9. Randa, thanks for the post. I had to redirect one of my biggest sites and it is so much easier to do it all through the htaccess file, instead of page by page. Thanks for your help.

  10. Ibnu Asad says:

    Thanks for the excellent post. Just what I was looking for :) I have one question though. Do I have to write “RewriteEngine On” and “RewriteBase /” every time I create a new redirect?

    Client Quotes

    Randa is an excellent graphic designer and communicator - not only did she reply to an urgent request in short time, she also delivered spectacular results. ~Ahmed Bilal


    Recent Work

    I recommend



    My Other Sites