[SOLVED][Drupal Commerce] How to redirect users to a secure domain?

| | 1 min read

Many Drupal users using the Drupal Commerce module who owned a number of domains but only a single secure domain with SSL wanted to know how to redirect users to that secure domain from the other domain. If you are faced with the same question in your Drupal site then read on to find out the solution.

Here is the solution suggested by a Drupal user.

  • First you need to install the Drupal Login One Time module
  • This will generate one time login links
  • Now we need to direct the user automatically to the new URL
  • Use the following code to do that
    function mymodule_hook_init() {
      if ($_GET['sendto']) {
        $timestamp = REQUEST_TIME;
        $url = url(
          "login_one_time/" . $user->uid . "/" . $timestamp . "/" .
           user_pass_rehash($user->pass, $timestamp, $user->login),
             'absolute' => FALSE,
        drupal_goto('https://' . $_GET['sendto'] . '.samplesite.com' . $url . '?destination=cart')
  • This will do an automated redirect and login to samplesite.com with along with a redirect to cart.

Hope that helps.

The easiest way to solve a Drupal issue is to hand it to the Drupal experts. We can provide a wide range of Drupal services to help you maintain and manage your Drupal websites. Get in touch with us to know more.