This is how you redirect all visitors to the HTTPS version of your Drupal website with or without WWW

Redirecting all your traffic from HTTP to HTTPS with or without WWW using Drupal can be a complex and frustrating task. Fortunately, there is a relatively simple solution that can help you achieve this in just a few steps.
Robert Roose
By Robert Roose

This is how you redirect all visitors to the HTTPS version of your Drupal website with or without WWW

Why Would You Want HTTPS?

When your website uses HTTPS, the connection between your website and the visitor is secured with encryption. Even if you don't consider this important yourself, internet browsers do. They display a warning when a website is offered over HTTP instead of HTTPS. This can make visitors distrust your website and choose not to visit it.

Why Redirect WWW to Non-WWW (or Vice Versa)

It's better to make a choice between offering your website with or without WWW to a visitor. It's possible to have both options active simultaneously, but this can lead to strange situations. Some search engines might consider them as two different websites, or an infinite redirect loop could occur between the WWW and non-WWW versions of a page.

Then there's the question of whether to choose with WWW or without WWW. There's no real reason to choose one over the other besides personal preference. I always omit the WWW because it takes more effort/time to type, so I prefer to keep it as short as possible.

That being said, I always communicate my own website with WWW to clearly indicate that it's a website (www.roose.digital). However, this is mainly because I have a unique top-level domain (.digital), and it's not always immediately clear that it's a website. Since I have set up a redirect to non-WWW, visitors automatically end up on roose.digital.

An SSL Certificate

Before we begin, it's important to have an SSL certificate. This enables an HTTPS connection to your website. You can obtain one for free through Let's Encrypt, among other options. Setting up an SSL certificate is a technical task. Fortunately, most hosting providers offer Let's Encrypt as a standard service, such as Cloudways.

Step by Step

  1. Install the HTTPS and WWW Redirect module and enable it
  2. Navigate to Configuration > HTTPS and WWW Redirect or use the following URL /admin/config/system/httpswww
  3. Turn on 'Enable redirects'
  4. Choose the option under 'Domain WWW prefix' that suits your preference. As described above, I choose 'Remove WWW prefix'
  5. For 'HTTP Secure (HTTPS) redirect,' select 'Redirect to HTTPS'
  6. Click on 'Save configuration'

Your website should now automatically redirect all HTTP and WWW traffic to HTTPS without WWW.

Do you have any questions about the above? Let me know by leaving a comment below.

The content of this field is kept private and will not be shown publicly.

Beperkte HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.