How can we help you today?

How to Redirect From or to WWW

Created by: Sophie van Vrijberghe de Coningh

Modified on: Thu, 4 Jun, 2020 at 10:10 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

To redirect all traffic to www use 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.