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

Need help with 301 Redirect

Discussion in 'General Programming Chat' started by propsta, Jan 21, 2013.

  1. propsta

    propsta Newbie

    Joined:
    Oct 29, 2009
    Messages:
    36
    Likes Received:
    8
    I run a decent gaming site that was running a CMS from 1996 (Custom). I recently migrated the entire site to Wordpress. The thing is I do not have a clue how to write the 301 redirect in the htaccess. Can some one help me.

    The site is http://www.mygamer.com/

    Some examples of 301s we need:

    http://www.mygamer.com/index.php?page=globalnews

    to:

    http://www.mygamer.com/mgwp/category/news/

    Remember the new WP site will be moved to root, so that subdir mgwp will be gone.

    http://www.mygamer.com/index.php?page=portal2&platform=&genre=&platform2=reviews

    to:

    http://www.mygamer.com/mgwp/category/reviews/

    There are a few categories I would need to do 301's with news, reviews, interviews, previews, articles. Id also need all content 301'ed.. LIke:

    Review:

    http://www.mygamer.com/index.php?page=gameportal&mode=reviews&id=556278

    to:

    http://www.mygamer.com/mgwp/staying-out-of-reach/

    Please can anyone help?
     
    Last edited: Jan 21, 2013
  2. ikstob

    ikstob Junior Member

    Joined:
    Nov 12, 2012
    Messages:
    147
    Likes Received:
    129
    Location:
    ikstob.com
    Home Page:
    You can do this by manually editing the .htaccess file at the top level of your <VirtualHost> DocumentRoot directory. Apache comes with a "RedirectPermanent" directive that does exactly what you need.

    Code:
    RedirectPermanent /blog/my-old-article-name.html /blog/2013/my-new-article-slug
    Be sure to place this *above* any stuff automatically added by Wordpress.

    e.g.

    Code:
    RedirectPermanent /index.php?page=globalnews /category/news/
     
  3. propsta

    propsta Newbie

    Joined:
    Oct 29, 2009
    Messages:
    36
    Likes Received:
    8
    Thanks man. I appreciate it. Is there anyway to automate this? I have over 60k articles, I dont think I could do that with all.
     
  4. Question

    Question Registered Member

    Joined:
    Aug 14, 2011
    Messages:
    51
    Likes Received:
    32
    I'm afraid it's only possible by writing some kind of script (PHP, Python, Ruby, etc.) that would do the job for you. I don't know how your database is organized, but you would need to match an article from your old database to an article in the WP database. Not really a hard task for an experienced programmer, but you seem to have not enough experience...

    Another possible solution is to redirect all traffic that matches "&id=%articleId%" pattern and then redirect it using a custom-made php-script... But either ways, you'll have to code some script.
     
  5. Gogol

    Gogol Elite Member

    Joined:
    Sep 10, 2010
    Messages:
    3,066
    Likes Received:
    2,872
    Gender:
    Male
    visit the site below
    Code:
    http://corz.org/serv/tricks/htaccess.php
    It has pretty much everything explained on htaccess. What I would do is take the something from page=something and replace it with /categories/something
    Just make sure that the new urls are named according to the old urls and I think you'll be redirect most of the urls...