<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>pingVision</title>
  <subtitle>Interactive Design + Development for Drupal websites</subtitle>
  <link rel="alternate" type="text/html" href="http://pingv.com/blog/laura/200511/creating-301-redirects-for-drupal"/>
  <link rel="self" type="application/atom+xml" href="http://pingv.com/node/3607/atom/feed"/>
  <id>http://pingv.com/node/3607/atom/feed</id>
  <updated>2008-01-07T09:22:50-06:00</updated>
  <entry>
    <title>Creating 301 redirects for Drupal</title>
    <link rel="alternate" type="text/html" href="http://pingv.com/blog/laura/200511/creating-301-redirects-for-drupal" />
    <id>http://pingv.com/blog/laura/200511/creating-301-redirects-for-drupal</id>
    <published>2005-11-26T12:54:51-06:00</published>
    <updated>2008-01-07T09:22:50-06:00</updated>
    <author>
      <name>Laura</name>
    </author>
    <category term="code" />
    <category term="Drupal" />
    <content type="html"><![CDATA[ <p>With the recent Jagger update to Google's search algorithms (more on this in a separate post), we've had more inquiries from website owners who are concerned about their sudden loss of PageRank and wish to port their sites over to <a href="http://drupal.org">Drupal</a>, but without risking a further hit on their site rankings through 404 errors. After all, it would be silly to seek out the myriad SEO advantages of a Drupal-powered website only to have search engines suddenly unable to find one's existing pages with hard-won search engine results.</p>
<p>While Drupal's built-in URL redirect features can seamlessly give any page any designated URL, such an approach might not be preferable if the existing pages have file suffixes or even paths with un-optimized paths.</p>
<p>The natural way to rectify this is by using <b>301 redirects</b> in the <b>.htaccess</b> file. However, the conventional approach won't work with Drupal; special syntax is required to achieve proper 301 redirects.</p>
<p>As a member of the Drupal community, and in the spirit of open source, I share with you the how-to copy I contributed to the <a href="http://drupal.org/handbooks">Drupal handbook</a>:</p>
<hr />
<p>If you are porting over an existing website to Drupal, one consideration is how you redirect the old page URLs to the appropriate pages on the Drupal version of the site. If you don't want to create custom rewrite paths within Drupal for those nodes -- or perhaps cannot due to clean URLs or filename suffixes -- then <b>301 redirects</b> are considered the best way to handle redirected pages, for they inform search engines to update their databases with the new paths. This way, you should not risk your <a href="http://www.seochat.com/seo-tools/pagerank-search/">search engine pagerank</a> or lose site visitors with <b>404 "not found" errors</b>.</p>
<p>However, 301 redirects cannot be done using <a href="http://www.tamingthebeast.net/articles3/spiders-301-redirect.htm">the common approach</a>. Yet establishing 301 redirects is quite easy, provided you have mod_rewrite enabled in your .htaccess file.</p>
<h3>How to create 301 redirects in Drupal</h3>
<p><b>Edit</b> your <b>.htaccess</b> file in a text editor. <i>[Note: Be sure to save the file in "UTF-8" format.]</i></p>
<p>In the file, you will find the commands:</p>
<div class="codeblock"><code># Various rewrite rules.<br />&lt;IfModule mod_rewrite.c&gt;<br />&nbsp; RewriteEngine on</p>
<p>&nbsp; # Modify the RewriteBase if you are using Drupal in a subdirectory and<br />&nbsp; # the rewrite rules are not working properly.<br />&nbsp; #RewriteBase /drupal</p>
<p>RewriteBase /</code></div>
<p><i>Immediately after</i> that code -- and before the Drupal-provided "Rewrite old-style URLs" commands -- add your rewrite rules using the following format:</p>
<div class="codeblock"><code>#custom redirects</p>
<p>RewriteRule ^/old/URL/path$ <a href="http://yourdomain.com/new/path" title="http://yourdomain.com/new/path">http://yourdomain.com/new/path</a> [R=301,L]</p>
<p>#end custom redirects</code></div>
<p>Note the convention: The <b>old path</b> is simply the path off the root. The <b>new path</b> is the full path, including the domain. The [R=301,L] code is the 301 redirect instruction. <i>(<a href="http://drupal.org/node/16084#comment-28642">axbom notes</a>: "The 301 tells browsers and spiders it is a permanent redirect, and the L ensures that no other rewrites are processed on the URL before it reaches Drupal; Hence place this code above Drupal 's own URL rewrite, but below the command RewriteEngine on.")</i></p>
<p>If you have more paths to add, insert the rewrite commands as their own line as above.</p>
<p><b>For more information</b>, <i>see</i> the forum thread at <a href="http://drupal.org/node/16084" title="http://drupal.org/node/16084">http://drupal.org/node/16084</a> [from where I drew this information]</p>
     ]]></content>
  </entry>
</feed>
