<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Web Cash &#187; HTTP</title>
	<atom:link href="http://www.earn-web-cash.com/tag/http/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.earn-web-cash.com</link>
	<description>Writing, Designing, and Making Money Online</description>
	<lastBuildDate>Sun, 04 Dec 2011 22:52:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>Moving WordPress: Individual 301 Redirects with PHP</title>
		<link>http://www.earn-web-cash.com/2008/03/23/moving-wordpress-individual-301-redirects-with-php/</link>
		<comments>http://www.earn-web-cash.com/2008/03/23/moving-wordpress-individual-301-redirects-with-php/#comments</comments>
		<pubDate>Mon, 24 Mar 2008 01:51:58 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Redirect]]></category>
		<category><![CDATA[seo]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/03/23/moving-wordpress-individual-301-redirects-with-php/</guid>
		<description><![CDATA[I recently decided to move part of an old blog to an independent site. In order to maintain the meager search engine and referral traffic that the old pages had, I planned on using 301 Redirects. I figured that I would re-create each of the old articles (~10 total articles) on the new site and [...]]]></description>
			<content:encoded><![CDATA[<p>I recently decided to move part of an <a href="http://walkere.frih.net/issues">old blog</a> to an <a href="http://rolling-horde.net">independent site</a>.</p>
<p>In order to maintain the meager search engine and referral traffic that the old pages had, I planned on using 301 Redirects.  I figured that I would re-create each of the old articles (~10 total articles) on the new site and set up an individual 301 Redirect to send users and search engine spiders to the new location.</p>
<p>The problem, however, was that the standard .htaccess rewrite that WordPress uses was conflicting with the 301 Redirects.  For some reason, they just weren&#8217;t working &#8211; so I turned to a PHP-based solution.<br />
<span id="more-180"></span></p>
<h4>301 Redirects In htaccess</h4>
<p>Normally, you can handle a 301 Redirect with a .htaccess file.  You can do this with a single line in your .htaccess file.</p>
<pre>redirect 301 /path/to/old/file.html http://newdomain.com/file.html</pre>
<p>The first part &#8220;redirect 301&#8243; indicates the <strong>type</strong> of redirect.  This tells the browser (or the search engine spider) that the page has <strong>permanently</strong> moved to the new location.  HTTP has several other options.  The 302 Redirect, for example, indicates that the move is <strong>temporary</strong>.</p>
<p>The next two parts indicate the old path to the file and the URL of the new location.</p>
<p>Normally, that&#8217;s all there is to it.  However, WordPress adds its own layer to the .htaccess file which makes your pretty URLs work.  The URL that you request is really just a bunch of variables that tell WordPress what article to pull out of the database and display in the template.</p>
<p>Although you should be able to get the two to work together, I couldn&#8217;t.  The server was ignoring my 301 Redirect and going directly to the other rewrite rules.</p>
<h4>Using PHP to 301 Redirect a WordPress Page</h4>
<p>The solution?  PHP.</p>
<p>Creating a 301 Redirect in PHP is fairly simple.  I&#8217;d read about it before, and just the other day I came across a <a href="http://www.electrictoolbox.com/php-301-redirect/">brief article about it</a> in one of my regular RSS feeds.</p>
<p>You use the header() function to send custom headers to the user&#8217;s browser.  With these, you can tell the browser that you want to initiate a 301 Redirect.  You can then tell the browser where to go to find the article.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HTTP/1.1 301 Moved Permanently&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: http://newdomain.com/article.html&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Simply replace the URL with the URL you want to redirect to.</p>
<h4>Making It Work With WordPress</h4>
<p>If you look in your site&#8217;s directory structure, you may realize that the path to your article doesn&#8217;t really exist.</p>
<p>Let&#8217;s say we want to redirect the article located at <a href="http://www.earn-web-cash.com/2008/03/20/useful-wordpress-plugins/">http://www.earn-web-cash.com/2008/03/20/useful-wordpress-plugins/</a>.  To use PHP, we&#8217;d need to create a PHP file to replace the article that is being redirected, and include the snippet of code above.</p>
<p>The problem is that the directory /2008/03/20/useful-wordpress-plugins/ doesn&#8217;t exist.  Those are parameters sent to the WordPress script to fetch information out of the database.</p>
<p>To make this type of redirect work, we need to <strong>create</strong> this directory structure.  Start at your root, and create the directory &#8220;2008.&#8221;  Create a directory &#8220;03&#8243; inside that.  Create a directory &#8220;20&#8243; inside that.  Finally, create the directory &#8220;useful-wordpress-plugins&#8221; inside that.</p>
<p>You&#8217;ll notice that there is a trailing slash in the URL.  In a normal directory structure, &#8220;useful-wordpress-plugins&#8221; is a directory, even though it would seem to represent the file where your article resides.  To get the browser to access a PHP file at this location, we place an index.php file in that directory.  Then, accessing the URL will automatically pull up index.php.</p>
<p>In short, create /2008/03/20/useful-wordpress-plugins/index.php, add the snippet of code above, and your redirect should work flawlessly.</p>
<p>This is a good way to move a few articles on a site to a new site.  If you&#8217;re moving an entire site, you&#8217;d definitely want to look into using the .htaccess method, or creating a PHP file that dynamically chooses what page to redirect the user to.  I only had to move 10 articles, so I created ten php files to do the work for me.</p>
<p>There is one caveat to keep in mind.  If your installation of WordPress uses the URL http://www.earn-web-cash.com/2008 to access the yearly archives, you&#8217;ll run into a problem.  /2008 will now be an actual directory &#8211; so the server will try to serve up the directory.  You&#8217;ll need to change your settings so that the archives are located in something like http://www.earn-web-cash.com/archives/2008.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/03/23/moving-wordpress-individual-301-redirects-with-php/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

