February 8, 2009

Global Redirect module not working on Drupal and nginx server?

Filed under: Tips — Tags: , , , — Webopius @ 7:16 pm

nginx is a small, powerful and lightweight web server often used as an alternative to Apache Tomcat. It was written by Igor Sysoev and has been used on a number of heavily loaded Russian websites.

Drupal and nginx work well together (see the previous VPS, Drupal, nginx post here) but you might discover that a few modules cause problems because of .htaccess or redirects written for Apache that do not work as expected on nginx.

Drupal’s Global redirect module is one possible problem area when using nginx. You type in an ‘old’ format /node/3456 and the content appears as you’d expect. However, the URL remains in the ‘old’ format.

This can potentially cause duplicate content issues in search engines.

The fix

To get Global Redirect module and nginx working correctly together, find the file /sites/all/modules/globalredirect/globalredirect.module.

At around line 46, you’ll see the line:

if ($_SERVER['SCRIPT_NAME'] != $GLOBALS['base_path'] .'index.php') return FALSE;

With nginx, this check doesn’t match and global redirect returns FALSE. So just comment this line out and all should be well.

  • Tags