Redirect WordPress Posts from an Old Domain

Simple Code

Recently I had a prob­lem when I moved my blog from blog.fantikerz.com to fantikerz.com. I had far too many links on other sites that still looked like http://blog.fantikerz.com/?p=261, and wouldn’t redi­rect to the new blog’s loca­tion. I wouldn’t even know where to start if I had to change all of those.

Instead, I threw together a sim­ple redi­rec­tion script that I thought I’d just share in case any­one needed it. It’s noth­ing fancy at all, and stu­pid easy to set up. There are many ways of doing this, and in my opin­ion, this is the easiest.

This is explained in a way that even com­mon folk who just want to move their blog will under­stand. Sorry if I insult your intelligence.

1. Cre­ate a file called index.php

Pop open notepad, go to File > Save As…, set the file­name as index.php, and then go directly below that and make sure to set Save As Type to All Files.

2. Copy the script into the text editor

<?php
	$post = $_GET["p"];
	$new = "http://newbloglocation.com";
	$string = $new . "?p=" . $post;

	echo "Redirecting to " . $string;
	header("Location: $string");
?>

3. Plug in your information

This is easy. Just plug in your blog’s new address where http://newbloglocation.com is. Make sure to include the http://. If your blog was located in another direc­tory, you’re also able to include it like so: http://newbloglocation.com/blog/. Oth­er­wise, omit any­thing after the domain name.

4. Presto, now save it and upload it to your server

Do a quick CTRL+S to save and upload it via FTP to the root of where your old blog used to reside.

Now you’re done. That was easy!

This entry was posted in Development, Extras, Information, Tech, Tips and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>