How to: Redirect users to a specific url using a 301 redirection

Do you know that WordPress have a built-in function to redirect users to a specific url? It is called wp_redirect(). Many users don’t know it, but you can also create 301 redirections with that useful function.

To create a 301 redirection within WordPress, you just have to add the 301 argument to the function:

<?php wp_redirect('http://www.wprecipes.com', 301); ?>

The above code will redirect anyone on my blog. Don't hesitate to use it :D

Related Posts

Related Posts

No related posts.

24 Responses

Dec 11 2008 19:10

And this works anywhere? It’s not restricted to being before anything is output, as header() is?

Dec 11 2008 19:28

@redwall_hp: No, it must be used before anything has been printed out. I have some problem with that function, and I must admit afterwards that it wasn’t a very good idea for a recipe. Anyways, let’s hope it will be helpful to someone :)

Dec 12 2008 05:39

Oh well. So I’m guessing the function is just a friendlier facade for header()?

Dec 12 2008 06:47

That’s simple :) Didn’t know there was a built in function. Not sure what I could use it for..

But always good to know all the features.. or most..

Dec 12 2008 19:00

There is a plugin Redirection (http://urbangiraffe.com/plugins/redirection/) that takes care of redirections.
Redirections are useful if there are errors or changes in urls of your site. I use Google Webmaster Tools – dashboard to see if there are any errors (URL not found). These I correctusing Redirection to point to the correct URL

Dec 12 2008 19:10

@fahirsch: I use this plugin, it is a must have in my opinion. Maybe i’ll talk about it on a forthcomming recipe.

Jan 23 2009 19:19

thank you, i am gonna try it.

Mar 08 2009 04:33

nice info, i’ll try it too.

Jun 02 2009 12:45

I really don’t know this word press function for the redirect, thanks to tell us about it.

Jun 14 2009 15:57

Great, I will use the code, Thank you.

Jun 21 2009 11:21

wow, i never knew that before. thanks, i am gonna try it asap.

Jun 25 2009 02:13

Great, i hope it works for me. I have much changes and now the bots are going to pages where are not longer available.

Jul 14 2009 14:40

very impressive, thanks for sharing this. keep up the great work.

greetjes

Jul 25 2009 01:09

Nice info, i’ll try it too.

Jul 27 2009 10:51

Thats simple, thanks for sharing.

Aug 13 2009 11:40

And if you have several urls to redirect?

Aug 23 2009 23:13

This is a nice tip, i will test it.

Sep 01 2009 00:39

Great, I will use the code, Thank you.
cu

Oct 09 2009 12:05

Super tip! Thanks for this feature! Greetings

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required