.htaccess and 301 Redirects in Drupal

Drupal

After updating/upgrading your website it is often necessary to define some 301 redirects to make sure end users don't come across a broken link or a file not found error. While defining a 301 redirect in your .htaccess file or through the cPanel of your webhost is not hard to do, it is easier just to download and enable the Path Redirect module. Drupal relies heavily on mod_rewrite and has a lot of rewriting rules defined so it is easy to get an infinite loop redirect when trying to edit the .htaccess file directly.

Updating Themes to Drupal 7

Drupal

I am in the process of upgrading my Drupal 6 theme into a fully functioning Drupal 7 theme and came across some issues that I wanted to document here as a reference to those in a similar situation. I followed my instructions here to create a local copy of my website and then I went through the typical upgrade procedure as outlined by the UPGRADE.txt file supplied by Drupal. There were a couple hiccups in the upgrade process, but a few simple Google searches led me to the answers to fully migrate my installation to Drupal 7.

I am planning on updating this page as my process continues and I find more changes.

Don't Forget to Print the $closure Variable on Custom Theme Pages

Drupal

If you have any modules that add external JavaScript to your pages (like Google Analytics), make sure you have the line <?php print $closure; ?> in your .tpl.php files right before the end </body> tag. If you don't have this line the external scripts will not be loaded and will not be added to your pages.

This should be the first thing you should check if Google Analytics is configured correctly on your site, but is not showing any data in the Google Analytics reports.

Custom Maintenance Theme Pages for Drupal 6

Drupal

Recently, I wanted to change the default "Site Offline" page that Drupal provides to a design that was less generic and more fitting with the style of the website. I needed to have the site in offline mode for a longer period of time while I was overhauling the content of the website. I developed a simple HTML placeholder page and by changing a couple lines of code in settings.php and adding a new function in template.php I was able to redirect the users to this static HTML page while the site was offline.

Top Ten Modules for Drupal 6

Drupal

Here are ten(ish) of my favorite modules to extend the functionality of Drupal.

 

 

Views & CCK

Often regarded as two of the most powerful modules in Drupal. You can create new fields to define different content types with CCK and choose different ways of displaying them with Views. Views is the easiest way of creating and displaying customized collections of content on your website, and Views can easily output its result to a node, block or RSS feed.

Backup a Drupal 6 Site to a Local Testing Server

Drupal

Over time, you may find that your production website and the local copy of your website become out of sync. You might find it necessary to create a backup of your site to place on your local machine so that you can test new development features.

 

1.

To do this you will need a local server on which you can run PHP and mySQL. I recommend using MAMP, WAMP, LAMP or XAMPP.

2.

Next you will need to make a back-up of your Drupal database. Many hosting solutions provide the ability to perform database back-ups through the control panel for your hosting account. Otherwise, you can download the Backup and Migrate module to perform a database backup through the admin interface of your website.

Accessing and Displaying Custom Profile Fields | Drupal 6

Drupal

Here are some PHP snippets to display data from custom profile fields you can set up using the core profile module in Drupal 6. In this first example I have a custom user profile field that holds the user's location with the machine-readable name of profile_location. The first block of code stores the location of the user who is logged in in the variable theLocation. The second block of code displays this value.

<?php
global $user;
profile_load_profile($user);
$theLocation = $user->{profile_location};
?>
<?php print $theLocation; ?>

Drupal 6 Custom Theme Template

Drupal

Here are some resources for creating a custom theme in Drupal 6.

The minimum files you need are:

  • .info file
  • page.tpl.php file
  • template.php file
  • CSS stylesheet

The .info file describes the basic information about your theme, including the name, description and version. It also allows you to define custom regions, and add new stylesheets or javascript files.