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
wwwDNS record must point to the NAS, usually with a CNAME todomain.be. - The TLS certificate must cover both
domain.beandwww.domain.be. - This
.htaccessmethod assumes the portal uses Apache HTTP Server and thatmod_rewriteis 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.
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.
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.
Discussion
Comments
No comment yet. Feel free to open the discussion with a question or your own experience.
Signing in keeps the discussion free of spam and avoids publishing your e-mail address.
Sign in to comment →