How can we help you today?

How to Redirect From or to WWW

Created by: Sophie van Vrijberghe de Coningh

Modified on: Tue, 6 Oct, 2020 at 11:31 AM


Many constructions are possible when it gets to the base URL. Some shop owners prefer a domain name starting with www, others prefer without.

There are some restrictions when choosing your base URL.

If you use the wwwizer servers, which are sometimes used when your domain is not hosted at Byte and thus the DNS can’t be automagically changed in case of up or downgrades, your domain will always redirect to www.

For Dutch customers only: when your domain is hosted at Byte, simply link it to your Hypernode through the Service Panel

More info can be found on our page about setting your DNS.

TABLE OF CONTENTS

Redirect From Apex to WWW

When hypernode-managed-vhosts enabled
To redirect all traffic to www you have to create both a vhost for the Apex and for the www. For the non-www vhost you can create the vhost as type wwwizer. This will redirect all traffic to the www. version of that vhost.

|    example.com |  wwwizer  | False  | False | False  |  True  | intermediate |
|www.example.com |  magento2 | False  | False | False  | False  | intermediate |


Without hypernode-manage-vhosts enabled (old legacy nginx-config)

You can redirect all traffic to www with the following Nginx snippet:

if ($http_host ~* "^example.com$") {
  rewrite ^ https://www.$http_host$request_uri;
}

Save this snippet in /data/web/nginx/server.rewrites.

Redirect From WWW to Apex

To redirect all traffic from www to the apex domain use the following Nginx snippet:

if ($http_host ~ ^www\.(?<domain>.+)$ ) {
        return 301 https://$domain$request_uri;
}

Save this snippet in /data/web/public/server.rewrites or in case you are using Varnish public.rewrites.

Redirect When Using Varnish

When you are using Varnish, the redirect will be cached, causing a redirect loop.

Instead you can use the public prefix, which is included before Varnish and thus will not be cached. 

Save your file as /data/web/nginx/public.rewrites

S
Sophie is the author of this solution article.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.