Redirect from or to www

in Nginx configurationUsage

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 typically 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.

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

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\.") {
  rewrite ^ https://example.com$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)

1