Drupal https login redirect

I launched the WFB Drupal site without a secure certificate on it so all our staff have the non secure “user/login” page bookmarked. Here’s a quick fix to get the login page redirected to https.

  • Site Building > Blocks > Add Block
  • Give it a meaningful description, and change the Input Format to “PHP Code” then paste the following:

<?
if ($_SERVER["SERVER_PORT"] != 443)
{
header(’Location: https://www.yoursite.com/user/login’);
}
?>

  • Select “Users cannot control whether or not they see this block.”
  • Select “Show on only the listed pages.” and put in “user/login” (without the quotes) in the Pages: section.

This approach also works for creating custom text on any Drupal generated pages, all you need to do is create a new block and paste in your HTML following the directions above.

Post a Comment

Your email is never published nor shared. Required fields are marked *