How do I add the "www." to a website i've set up to have no www. (example: mydomain.com --> www.mydomain.com)

Any answers would be greatly appreciated!

Dani AI

Generated

Short answer: add a permanent (301) redirect for the naked domain to the www host, or use your registrar/CDN to forward the apex. Verifying both forms in Search Console (as mentioned) helps reporting, but it does not redirect visitors — Google removed the old “preferred domain” control and prefers redirects / canonical signals instead. (See Google’s note.) Bye Bye Preferred Domain setting

Options (pick one that fits your host):

  • Server (recommended if you control the webserver). Example alternatives to the .htaccess rewrite shown by :
# Apache (in your virtual host for example.com)
<VirtualHost *:80>
    ServerName example.com
    Redirect 301 / http://www.example.com/
</VirtualHost>
# NGINX (server block to preserve scheme and path)
server {
    listen 80;
    server_name example.com;
    return 301 $scheme://www.example.com$request_uri;
}
  • CDN / edge rule (no server change). Create a forwarding rule (pattern example.com/* -> ) and choose 301; Cloudflare and similar providers offer this. See Cloudflare forwarding/redirect guidance. Cloudflare Page/Redirect rules

DNS notes and pitfalls:

  • You cannot reliably use a CNAME at the zone apex; use an A/AAAA, an ALIAS/ANAME if your DNS provider supports it, or let the registrar/Cloudflare handle forwarding/flattening. (Docs from AWS/Cloudflare explain the alternatives.) Route 53 alias vs CNAME · Cloudflare CNAME flattening

Practical cautions:

  • Use 301 (permanent) for SEO consolidation (Google recommends redirects/canonicalization). Consolidate duplicate URLs
  • If you use HTTPS, make sure your TLS certificate covers both example.com and www.example.com (a wildcard like *.example.com does not, by itself, cover the apex unless the apex is explicitly included). Wildcard / SAN notes (DigiCert)

Quick test (after change):

curl -I http://example.com
# expect "HTTP/1.1 301" and a Location: header pointing to the www URL

If redirects loop, check for double redirects (HTTP -> HTTPS and then non-www -> www); fix by consolidating rules and ensuring certs and DNS are set for both names.

in google webmaster tools you just verify both the www.yourdomain.com and yourdomain.com you then go to setting and choose which one you want to appear in webmaster tools settings

okay, yes. but change it on my domain. so instead of it being domain.com it literally appears as www.domain.com

you can do that from htaccess, add the following code :

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$  [R=301,L]
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.