WordPress "Page Redirect" template

Have any page in the Wordpress "Pages" list invisibly redirect to a static page or other url

Posted on Wednesday, February 20th, 2008 at 2:43 pm

The very nature of WordPress demands that you work within it's infrastructure in order to maintain flexibility. Sometimes, though, the structure of your pages demand that you need to operate outside of this constraint.

This template lets you specify a single URL as the page content, then as the page loads, the template automatically redirects the page to this new location.

Usage

Once you've uploaded the template-redirect.php file to your themes… sub-directory, i.e. wp-content/themes/theme_name/

1 – Create a new Page in your WordPress control panel

2 – In the Page Content panel, just enter the URL (or local path) you want to redirect to:

3 – Set the Page Template dropdown to "Page Redirect":

That's it!

Note that in WordPress 2.7 and later, you will need to do a little additional setup work to display the page template dropdown (don't ask me why).

See this link for further details.

Examples

Examples of URLS might be:

  • category/flowers (a relative link to the permalink for "flowers")
  • ../page.html (a page outside of a WordPress subfolder (the WP folder being /blog/) but still in your site)
  • http://www.davestewart.co.uk/resources/ (a page on a completely different site)

The "Latest developments…" page in my sidebar automatically redirects to /category/development/ – or in other words, the archive for my "Development" category, as my home page is not the standard "last-post first" format.

Download

template-redirect.zip

61 Responses to “WordPress "Page Redirect" template”

  1. Alexander A. Carde' |

    OMG You are a lifesaver. I've litterally spent 20 or 30 hours trying to figure out ways to do this. I even starting learning PHP. I am NO programer just a basic techy. Might site is not ready yet because I was waiting to figure this out. If you find out a non-hacked way to do this PLEASE let me know. Now I have to get on design and layout, not to mention other stuff.

    Again, THANK YOU!

    Alexander

  2. Dave Stewart |

    Hey Alexander,

    I'm glad it's working for you!

    I'm not sure what you mean by "non-hacked" though? If you mean you want a solution that works solely within the core WordPress functions, then I don't know, to be honest. As far as I can tell in my limited usage of WordPress (ie, this blog) and the woefully-incomplete help, "page"s and "post"s are just database entries – that's just how WordPress works, so the management of static content falls outside this paradigm (and thus "hacks" like this).

  3. Pranav |

    Came across this searching Google for a method to redirect pages to categories :)
    I guess this is the best way ever to do it. Thanks a ton, Dave. And a nice blog ;)

  4. Geoff |

    nice clean solution…using pure Javascript in the source of the page has a visible "hiccup". thx !

  5. Allen Blair |

    Thanks greatly for this!!! This is exactly what I have been looking for. One more obstacle on my list taken care of by the wonderful wordpress community. Kudos.

  6. Dave Stewart |

    Thanks for the thumbs-up, chaps!

  7. Govvy |

    I would just like to say… Thank you. :)

  8. LSMDB |

    Hey,

    One small problem – after installing the template and setting up two redirects, my site no longer gives out "404 – Not found" errors. All it does when someone types a wrong URL is point them to the first redirect I set up. You can try and see for yourself.

    Any idea why this could be?

    Thanks,
    Sebastian

  9. Dave Stewart |

    Hi Sebastian,
    Well that's strange, because all the page does is grab the text from the post content, and redirect the page to the new location; it's really very uncomplicated, so I don't really see how it could affect your 404 page.
    What happens if you remove the template links?

  10. james |

    doesn't work. i followed the directions–created a new Page, included the redirect URL as the only content, Saved and Published.

    i'm trying to redirect incoming traffic from a page that was deleted to my main page, by the way. so that when they click a link, they bypass the error result from a deleted page and go right to the Home page.

    cheers,
    -james

  11. Dave Stewart |

    Hi James,
    What was the exact URL you placed in the content area?

  12. james |

    http://www.mydomain.com

    just like that (with "mydomain" replaced with a real one, of course.)

  13. Dave Stewart |

    Hmm. Not sure why it's not working for you, as it does here. To test, I've added a new page to my top links, "Dave Stewart", and that's just "http://www.davestewart.co.uk", and it works fine. Check it out, as I'll delete it in a day or so.

    Another option you could use would be to add an Apache Redirect Directive to an .htaccess file in your root directory, which would redirect traffic at the server level, rather than the page level: http://www.base64.co.uk/apache-redirect-directive/

    And if you want to email me, feel free.

  14. ethan |

    Neat trick. My only suggestion is that $HTTP_SERVER_VARS is, I believe, deprecated in PHP 5. People should be using $_SERVER. I made this modification and it works fine.

    Thanks, though. This is way simpler than the Redirect plugin I found.

  15. Dave Stewart |

    Cool. Thanks Ethan – I've updated it now :)

  16. Alex |

    hi. it works great, 1 question from me:

    Is it possible to redirect the page to an alternative site IN a new windows?

    1000 thanks

  17. murtaza |

    looking for solution that i type my url and is redirected to new static page

    and how it can be done from the post…. is their anyway to do from post

    thankyou and looking forward for your prompt reply

  18. Dave Stewart |

    Hi Murtaza,
    Sorry – I can't help you there! Page Redirect does one thing and one thing only.
    Cheers, Dave

  19. Jerry |

    Here is an even simpler solution. If your permalink options are not set to the default option, just make the permalink the link that you want the page to be redirected to. I don't know how deep you can go but it's worth a shot.

  20. Richard |

    Awesome. Thankyou very much

  21. daniele |

    I think (just for searchbots happiness) it would be better add a 301 header before redirect:

    // do the link
    —–> Header("HTTP/1.1 301 Moved Permanently" );
    Header("Location: $link");
    die(");

    thanks a lot for your page-redirect-template. It solved my need in just one second!

  22. Laurens |

    After trying two plug-ins that seemed either buggy or complete overkill I stumbled upon this page and find a 1-minute fix for my problem. Brilliant – thanks!

  23. The Local Landing |

    Your plugin is working great, but there's one problem I've come across when trying to use it.

    We're using the Post Template Plugin, and I'm trying to point your plugin to redirect to a specific plugin we've made. This is the URL for the specific template:
    http://www.thelocallanding.net/wp-admin/edit.php?page=post-template/includes/manage-templates-page.php&action=create-post&template_id=6

    I've put that in the page to be redirected and set everything else accordingly (works fine with simpler links), but it seems that it will only redirect to
    http://www.thelocallanding.net/wp-admin/edit.php?page=post-template/includes/manage-templates-page.php

    leaving off the "&action=create-post&template_id=6". This shows a list of all templates we've made with the Template Plugin, but I cannot for the life of me convince it to keep that vital last part of the URL which would lead directly to the specific template I want to redirect to.

    I don't know much about this type of thing, but if you can think of any way to persuade your plugin to keep the full url, I'm sure world peace wouldn't be far behind!

    Thanks for the plugin, and any help you can give on this issue. :)

  24. Becky |

    Add another thanks to the pile! :D This is perfect – and no hiccups!

  25. Jim |

    I'm trying to use it for WP 2.7 and it doesn't appear to be working. There is no section that allows me to choose page redirect on the "page" page.

  26. Thanks!!! |

    Thanks! You just made my day :D

  27. Melanie |

    Hmmm…is there more to it? I uploaded the php file to my themes directory. But when I go to the template drop-down, the redirect option is not there. What can I do? I tried also uploading the redirect folder to my themes directory, with no luck. How'd everyone else get it to work? Are there limitations depending on which version of WP you have?

  28. Criss |

    Great!
    It also works with multiple languages (polyglot plugins)

  29. Ipstenu |

    DUDE! This rocks! Thank you so very, very much!

  30. Dofollow Social Bookmarking |

    All I can say is great tip… It took me 5 hours to discuss with my host how to redirect one of my pages to my main site and he finally advised me to search google.. LOL.. Now I know my host still did a good job by giving me suggestion…

  31. andy |

    This is what I've been looking for thank you, because before I have to link within my page which is very inconvenient, the user has to click two times…thanks a lot!

  32. Thomas |

    This works great, thats for the help. Is there a way i can make this load a page in a new window rather than in the same window? Im a bit of a newb here and this script has helped a load. Thanks again.

  33. The Pimp Panther |

    This is why I always found geeks to be so sexy! Always love to see some brains! Big muaaahhh and thank you for the great solution!

  34. Dun |

    Thank you. I have been trying to figure this out for a while now.

  35. 30+ (More) Most Wanted Wordpress Tips, Tricks and Hacks | My Tech way |

    [...] WordPress ‘Page Redirect‘ template [...]

  36. Dave Stewart |

    Sorry to anyone who's left comments asking for help over the past VERY long while, I'm not really giving the blog much attention these days. I hope you all worked out your issues :)

  37. spacemonkeymike |

    thanks for the plugin Dave, for anyone that might have making this work, the key is to installing the template page redirect pho file is to put it in the folder of you actual theme rather than your /theme root.

    For example if you are using a theme named spacemonkey, you should probably put your theme in a folder like /wordpress/wp-content/themes/spacemonkey.2.2/spacemonkey
    where all the other .php files are.

    Hopefully this will same someone a few minutes of their time.

  38. Dave Stewart |

    Fair point Mike. I've updated the main post.

  39. SmsVar, Sms Gönder, Toplu Sms |

    this is thank you..

  40. Greg Downing |

    Thanks so much!!

  41. pesky |

    Hi there – thanks so much for such an elegant solution!!

    one question – if i have adsense on my pages (i do), will this get me in trouble with them? adsense requires a certain amount of text on my pages as per their terms of service, and if it isn't there it can get you knocked off their program.

    i know this works for humans, but will a bot 'read' the page as empty, besides a URL?

    i guess i could write any old rubbish after the url (?), but i thought i'd check with the geniuses here

  42. rendy |

    thanks you very much..

  43. Jennylee |

    It's spooky how clreev some ppl are. Thanks!

  44. Yuri |

    Hi Dave,

    Great stuff!

    Question: how can insert my Google Analytics (or any other tracking) code into this page? Will inserting "get_header();" as the first line of code do the trick (my GA code is in the header)?

    Thanks!

    Yuri

  45. Deano |

    Works great, unlike so many others I've seen on the web!

    Check it out in action – http://japantravelmate.com/ – the very top leaderboard banner has a URL "http://japantravelmate.com/japan-rail-pass/", however using the method from this post, redirects using my affiliate link!

    I'm a very happy webmaster, thanks!

  46. Lucien |

    Hi Dave, I think this is what I need to create a button on my WP page that will take the reader to my WP blog?

    I have ftp access but I don't know how to upload to it. I can't just drag the php thing to the page.
    So I get stalled on this first thing:
    Once you’ve uploaded the template-redirect.php file to your themes… sub-directory, i.e. wp-content/themes/theme_name/

    Hope I'm missing something simple!
    Thanks, regards,
    Lucien

  47. Lucien |

    OK, I found it. But it failed to install it because it was missing a style.css thing. Might your handy thing not work anymore?
    Thanks,
    Lucien

  48. James |

    Thanks for this great script! However, it doesn't work if you set the URL to https. The redirection URL gets appended to the source page.

    I had to edit the template php so it looked for https instead of http, towards the bottom.

  49. dk |

    Thank you very much. Really nice fix for sending to the first child of a page.

  50. Eric Downs |

    Brilliant!

    I never comment on blogs but I had too just because this is such a time saver.

    Thanks

  51. Chris |

    Is there a way to use this redirect with a time delay?

    I need for my users to be able to view the wordpress page for a few seconds, then be redirected to another page.

    Can you give me the code to add to your template-redirect.php to do this?

  52. Fiona |

    I know it's been about two years since the last comment was posted, but I thought I'd try anyway.

    First off, thank you! This saved me a huge head ache!

    Second… Is there a way to make the redirect remain on the current page, but just go down to an anchor tag? I'd like it to just redirect to the footer. Currently, it redirects to the home page, then the footer.

    If this isn't possible, that's okay. Going back to the home page isn't bad.

    Thanks!

  53. Pauldz |

    Dave,

    I've been looking for a solution like this for a long time. As a blog newbie, this is a lifesaver! I can't believe how easy it was to integrate into my wp theme. Many thanks.

  54. Rafael |

    Excellent, thanks for the input. Works correctly in WordPress 3.5.2.

  55. Trane |

    I'm trying to link to an outside domain… This fix reads like it's what I'm looking for… but when I publish it; the URL string is added to the domain/subfolder that the page resides in… I get redirected to :http://ceracom.com/wp_ceracom/https://www.cera.net/portal/cart.php?gid=13

    instead of just the catalog.

    I've tried ../../ to escape up. but that didn't work either.

    Anyone else have this problem?

  56. Pauldz |

    I upgraded to the newest version of wordpress, and this template disappeared. I tried re-installing it, but got this error message:

    The package could not be installed. The theme is missing the style.css stylesheet.

    Any suggestions?

  57. Victor |

    Not working for me. Latest wordpress version

  58. Mike Mai |

    Hi, this works nicely, there's one issue though. The page using this template still exists, you can get there by typing .php after it.

    Let's say I created "/work" page using this redirect template, which redirects to "/work/recent". It redirects if I go to "/work", but if I go to "/work.php", it'll go to the actual page and not redirect. Is there a fix for this?

  59. Dave Stewart |

    That's probably an internal thing. I've added it to the list of issues, which I'll tackle shortly: https://github.com/davestewart/wp-template-redirect/issues/1

  60. Dave Stewart |

    Hey Paul,

    Sorry, have not looked at WordPress or this plugin in quite a while.

    Did you get it sorted?

  61. Dave Stewart |

    NOt sure, Mike, I'll look into it.

    Have a currently added this to the GitHub issues: https://github.com/davestewart/wp-template-redirect/issues/2

Make a comment or suggestion...