www resolution

The site works whether users type www or not.

On this page

Impact

ScanGov impact ratings

About

Domain canonicalization allows access to the intended website address, whether users type www (www.example.gov) or not (example.gov). Improper canonicalization will fail to direct example.gov to the intended address, and users will receive an error.

Risks

Users get errors when typing your web address.

Why it's important

Ensures consistent site display whether users type with or without 'www,' preventing errors and improving overall accessibility.

User stories

As a site visitor, I want to access the website using either www or non-www URLs and be automatically redirected to the correct version so that I don't encounter errors or duplicate content.

Code

nginx — redirect non-www to www (or www to non-www, pick one canonical form):

# Redirect www to non-www
server {
  listen 80;
  server_name www.example.gov;
  return 301 https://example.gov$request_uri;
}
server {
  listen 443 ssl;
  server_name www.example.gov;
  return 301 https://example.gov$request_uri;
}

Error

ScanGov messaging when a site fails a standard:

www and non-www versions are inconsistent.

Examples

Example of a government website with www and non-www resolution:

Guidance

Indicators

On this page