1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Wordpress Redirect All Posts

Discussion in 'PHP & Perl' started by Nolshestoy, Jan 31, 2014.

  1. Nolshestoy

    Nolshestoy Newbie

    Joined:
    Mar 26, 2013
    Messages:
    42
    Likes Received:
    1
    Hello,

    does someone maybe know how it's possible to redirect all posts to a certain URL? I mean, I have the php code ready, but I don't really know where to add that. What page is required to make that work for every post? Or is there a plugin for this?

    Help would be appreciated!
     
  2. Schvamp

    Schvamp Power Member

    Joined:
    Feb 13, 2012
    Messages:
    684
    Likes Received:
    549
    Location:
    Hogwarts
    Paste it in Single.php to redirect all posts. Header.php for the whole site or just redirect the whole domain from your control panel.

    Code:
    <meta http-equiv="refresh" content="0;url=[I]http://domain.com[/I]" />
    
     
  3. peetrike

    peetrike Power Member

    Joined:
    Aug 19, 2012
    Messages:
    585
    Likes Received:
    216
    Location:
    Estonia
  4. Puppetmagic

    Puppetmagic Junior Member

    Joined:
    Jan 21, 2013
    Messages:
    114
    Likes Received:
    60
    Occupation:
    Milking Cash Cows
    Location:
    Beneril
    dont know of such a plugin but i have previously used one where you can redirect each page or post to another url. but you can only do this one by one.
     
  5. mypmmail

    mypmmail Junior Member

    Joined:
    Jan 31, 2008
    Messages:
    111
    Likes Received:
    27
    In your wordpress theme,
    under wp-content/themes/your_theme directory,
    you can either edit the header.php directly or
    you go to your wordpress admin, Appearance | Editor and add the redirect code in the header.php

    Hth
     
  6. Nolshestoy

    Nolshestoy Newbie

    Joined:
    Mar 26, 2013
    Messages:
    42
    Likes Received:
    1
    That doesn't work unfortunately. I actually get every page of Wordpress redirected, except the post page. I also have a loop of different URL's to which every post should be redirected.
     
  7. Nolshestoy

    Nolshestoy Newbie

    Joined:
    Mar 26, 2013
    Messages:
    42
    Likes Received:
    1
    If it would be that easy, I wouldn't write a thread. As I said, I tried everything and nothing works, also I have a loop of different URL's to which every post shall be randomly redirected. These plugins are only for one URL and too complicated if you have to set every post individually up.
     
    Last edited: Jan 31, 2014
  8. Nolshestoy

    Nolshestoy Newbie

    Joined:
    Mar 26, 2013
    Messages:
    42
    Likes Received:
    1
    I already edited the header.php and as I already mentioned it redirects every page except the post page.
     
  9. Schvamp

    Schvamp Power Member

    Joined:
    Feb 13, 2012
    Messages:
    684
    Likes Received:
    549
    Location:
    Hogwarts
    It's really hard to know what you're talking about when you've got several answers. Saying "THAT doesn't work" wont help us to understand your problem.
    You use a catch plugin?

    So sad to see the other responders telling you to get a plugin for such a simple thing. No wonder WP sites keeps getting hacked when everyone need a plugin to change the font color, re-size an image, change background or adding a signature at the bottom of the post.

    EDIT
    You have some mess-up theme that doesn't load the header?
    Single.php's first line should be <?php get_header(); ?> in order to load header.php
     
    Last edited: Jan 31, 2014
  10. Nolshestoy

    Nolshestoy Newbie

    Joined:
    Mar 26, 2013
    Messages:
    42
    Likes Received:
    1
    What's hard here to understand? I simply want to redirect all the posts to several URL's which change randomly. Your idea doesn't work!
     
  11. thraxx

    thraxx Newbie

    Joined:
    Nov 20, 2008
    Messages:
    25
    Likes Received:
    6
    No plugin necessary. You should use .htaccess.
     
  12. Nolshestoy

    Nolshestoy Newbie

    Joined:
    Mar 26, 2013
    Messages:
    42
    Likes Received:
    1
    I see now, your method works but it opens the page first, then redirects after 5 seconds or something.

    Don't you have a better solution, where it redirects instantly?
     
  13. Nolshestoy

    Nolshestoy Newbie

    Joined:
    Mar 26, 2013
    Messages:
    42
    Likes Received:
    1
    Any code available?
     
  14. Imgar

    Imgar Newbie

    Joined:
    Jul 22, 2012
    Messages:
    24
    Likes Received:
    12
    Home Page:
    so you don't need all the existing posts/pages right?
    Add following codes to your header.php, at the very beginning of <head>;
    Code:
    <?php
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: target"); 
    exit(); 
    ?>
    

    Remember to replace target with your own link.
     
    Last edited: Jan 31, 2014
  15. mypmmail

    mypmmail Junior Member

    Joined:
    Jan 31, 2008
    Messages:
    111
    Likes Received:
    27
    I suppose you are using html refresh if it's 5 seconds.

    Just change the time to 0

    Code:
    <meta http-equiv="refresh" content="0; url=http://example.com/" />
    
     
  16. Pawtoen

    Pawtoen Newbie

    Joined:
    Feb 7, 2014
    Messages:
    37
    Likes Received:
    12
    301 redirection will better maybe
     
  17. Jcouch

    Jcouch Newbie

    Joined:
    Jan 22, 2014
    Messages:
    9
    Likes Received:
    4
    Depends what you are trying to do, you have not really given enough information here.

    Here's your options, and me guessing at your situation.

    A. Do a 301 redirect (You can do this from your registrar, or an .htaccess file, this is the simplest way to 301 the entire domain to a new location.)

    B. If your on a subdomain, or moved the old blog to a new directory, you can run an sql query via phpmyadmin. You want to run a search and replace on the wp_posts table. I'll assume you've already ported/moved your site to the new location - So run a search and replace query on wp_posts/wp_posts meta and replace olddomain with newdomain. This will leave the old site intact, but all the links will lead to the new location.