Redirect an old hostname to new hostname using mod_rewrite and Drupal

I was browsing through the referer logs in my website and noticed Drupal was serving content to my old hostname, http://oolportal.com . SEO gurus also suggest it’s a bad idea to serve the same content from multiple domains, and that you can transfer link value using a redirect. Over the long run I want the references to all end up going to http://poweredbyjeff.com so it’s time to take corrective action.

The simplest way I have found to achieve this is to have Apache’s mod_rewrite simply send the browser a 301 “permanent redirect” whenever my old hostname is requested. I find .htaccess to be some voodoo… the documentation is intense reading and best done after lots of sleep and at least 2 cappucinos. Also make sure you have brushed up on regular expressions if you want to understand the fine detail here. Having said that, here is my solution:

1
2
RewriteCond %{HTTP_HOST} ^(.*)oolportal.com$ [NC]
RewriteRule ^(.*)$ http://poweredbyjeff.com/$1 [R=301,L]

These 2 lines are added to my Drupal installation’s .htaccess file just below the sections for adding/removing the www. prefix automagically. Works a charm, you can try it by replacing “poweredbyjeff” with “oolportal” in your browser and see the redirection magic!


Fighting spam in Drupal 7 - disable the homepage field on comments

Spam is really annoying, particularly for anybody maintaining a website with anonymous contribution - in my case via comments. Mollum filters the bulk of the spammers out. Unfortunately if you want to capture anonymous commenter’s contact information in Drupal 7 this also exposes and displays the homepage field. This is also displayed to all visitors to your website that can access this content - incentive for link spammers :(

If you don’t care about following up with your commenters, or you only allow commenting by registered users - the email and homepage field on anonymous comments can be disabled here:

Administration -> Structure -> Content Types -> [choose relevant content type] -> Comment settings -> Anonymous commenting

This however doesn’t work for me - I like to be able to reach out to legitmate commenters via email and require it (but don’t display it). I don’t care for the homepage field. The easiest and quickest way to disable the field is to add the functionality yourself via a module. Adding this in a simple module should do the trick (I stuck it in my “jeff_hacks” module, you need to update the prefix to your module name):

1
2
3
function jeff_hacks_form_alter(&$form){
$form['author']['homepage']['#access'] = FALSE;
}

Drupal 7 missing 'Manage Display' in Content Types

Had an interesting issue when installing Drupal 7 the other day. I could not find the “teaser length” feature that was present in Drupal 6. This appears to be expected behaviour, however I could not see the “Manage Display” and “Manage Fields” options in the Content Types settings.

If you selected the “minimal” profile during install, the “Field UI” module will not be enabled. Turn this on and the “Manage Display” along with “Manage Fields” become visible and you can follow your nose from there.


Website is back!

Couldn’t help it, had to put something here. I pulled down the site some months ago (perhaps as many as 12). I think the goal at the time was to upgrade to Drupal 7, but as often happens life got in the way.

Some key goals with this site:

  • Easy to maintain - Drupal 7 does the trick here, I’m familiar with it and it’s looking pretty kick ass out of the box.
  • Resume - will store my resume here for reference (and hopefully future employers!)
  • Documentation - particularly for my project work. My home server is a great example… it’s a bit hard to remember mdadm commands 18 months after you set up a Linux software RAID. Also not a good idea to store the maintenance instructions on the device itself ;)
  • Keeping the chops in shape - good to know I’m still able to play with webpages if the need arises. Besides it’s fun.