Synology and Web hosting 6 min read

Synology Web Station: adding www to a site

Setting up a www portal in DSM 7.2, redirecting it to the main domain and avoiding duplicate URLs.

Hello everyone. In this guide I show how to make a site hosted in Synology Web Station reachable both from its main domain and from the www subdomain. I also explain why it is usually better to keep a single reference address.

Do you really need www?

In the early days of the Web, the www prefix often served to distinguish the Web service from other services such as FTP or DNS. It is no longer required. A site works perfectly well on domain.be without using www.domain.be.

Those two addresses remain two different host names all the same. If they show the same content, pick one canonical address and redirect the other permanently. That consistency avoids duplicate URLs, consolidates search signals and simplifies your statistics.

Before you start

  • The main site must already work in Web Station.
  • The www DNS record must point to the NAS, usually with a CNAME to domain.be.
  • The TLS certificate must cover both domain.be and www.domain.be.
  • This .htaccess method assumes the portal uses Apache HTTP Server and that mod_rewrite is allowed.

Adding the redirect in .htaccess

Open the .htaccess file at the root of the site and add the block below. Make a copy of the file before any change.

# REDIRECT FROM WWW TO THE MAIN DOMAIN
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
</IfModule>

Put this block at the top of the file or, for WordPress, before the # BEGIN WordPress line. Rules placed between # BEGIN WordPress and # END WordPress can be rewritten automatically by WordPress.

The redirect block selected in the Synology text editor, shown with a French interface
The redirect block sits before the rules managed by WordPress.

Creating the www portal in Web Station

Open Web Station, then Web Portal. Create a portal for the same service as the main site, or edit an existing portal. Choose the Name-based type, enter www.example.be as the host name, select the ports in use and apply the configuration.

Creating the www.example.be portal in Synology Web Station, shown with a French interface
The www.example.be portal uses the same Web service as the main domain.

Checking the redirect

Open a full URL with www, including an internal path. The browser must land on the same path without www. For a quick check on the command line:

curl -I https://www.example.be/guide/test

The expected answer is a permanent 301 status with a Location header pointing to https://example.be/guide/test. Also check that there is no loop, that the certificate is valid and that the canonical address declared by the site is the right one.

In short

Web Station makes it easy to add the www host name. The important part is not to publish two independent versions of the same site. Pick your main address, use it in internal links and in the sitemap, then redirect the other version.

References

About the author

Jeremy Kraft runs the infrastructure and the self-hosted services of the IBCSC. These guides describe configurations that were actually deployed and re-checked before publication.

Discussion

Comments

0

No comment yet. Feel free to open the discussion with a question or your own experience.