301 of subdirectory with dynamic URLs

Discussion in 'Apache' started by Briongloid, Jul 5, 2011.

  1. #1
    This is driving me nuts!

    There's an old blog in a subdirectory which I want to 301 redirect.

    It's no problem to redirect the main directory itself using .htaccess
    i.e.

    www.blah.com/oldblog to www.blah.com/newblog

    The problem is I also need to redirect all the old blog posts, which are dynamic, to the new blog permalinks.

    i.e.

    www.blah.com/oldblog/?p=10

    to

    www.blah.com/newblog/2011/01/01/permalink-of-post

    I'm pretty sure this can be done I've just no idea how to do it, was hoping some htaccess ninja could enlighten me
     
    Briongloid, Jul 5, 2011 IP
  2. MartinPrestovic

    MartinPrestovic Peon

    Messages:
    213
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Unfortunately there is no easy way to do this because it's not possible for htaccess to know what the "permalink-of-post" portion of the new URL is going to be. It will be different for every single post. So the only way to do it is the same method you use for the main directory.

    If you have loads and loads of posts to do, you could knock together a PHP script to access the database directly and generate the output for you so that all you have to do is copy and paste it into your htaccess file.
     
    MartinPrestovic, Jul 6, 2011 IP
  3. Briongloid

    Briongloid Peon

    Messages:
    89
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for your answer. I guess the best thing to do is just redirect the whole directory then.

    There's only a few posts and no backlinks pointing at them near's I can see so the PHP script would be overkill in this situation. Just thought I could do it nice and neat with .htaccess. In any event, thanks for your help, and something to consider next time around. :cool:
     
    Briongloid, Jul 7, 2011 IP