Apache: remove WWW
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L,NE]A new site commonly uses the shorter non-WWW address. For an established site, retain the version already used in advertising, links and search.

Replace the domain and reverse the direction if needed.
Hello, Please configure a permanent 301 or 308 redirect for example.com from www.example.com to example.com. Preserve page paths and query strings, redirect directly to HTTPS and avoid a chain of multiple hops. Please confirm whether this is included in the hosting plan. Thank you.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L,NE]RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L,NE]server_name www.example.com; return 301 https://example.com$request_uri;
The full block, ports and SSL must match the server. Validate configuration before reloading.
Bad: http://www.example.com → http://example.com → https://example.com Good: http://www.example.com → https://example.com
Bulk changes to links, canonical, sitemap.xml, robots.txt and advertising URLs are separate tasks. Restore the backup if a loop appears.