Ashley Cameron Design

Ashley Cameron Design

Shop the Creative Design Market

Good morning
Preferred Domain Google Wordpress

How to set a preferred domain (with steps for WordPress)

This post was last updated: Sep 6, 2022
BlogWordPress

About a 2 minute read

"Design is a formal response to a strategic question."

Mariona Lopez, business owner

Decide a preferred domain format:

  • http://example.com
  • http://www.example.com
  • https://example.com
  • https://www.example.com

WWW vs non-WWW SEO Benefits

There’s no SEO advantage of using www vs non-www on a small website; it’s a personal preference. Consistency using the same format is what’s important. When you add www, it acts as a hostname with can help with flexibility to the DNS and the ability to restrict cookies when using multiple subdomains and more. Learn more technical jargon here.

Set a preferred domain in WordPress

In General > Settings, your WordPress Address & Site Address should use the preferred domain format. Ex:

WordPress Address (URL): http://example.com/wordpress/
Site Address (URL): http://example.com

OR in wp-config.php:


1
2
define('WP_HOME','http://example.com/wordpress/');
define('WP_SITEURL','http://example.com');

Set a preferred domain in Google Search Console

Go to your Google Webmaster Tools account. Add and verify ALL variations of your website. If you have an SSL, add the https formats with and without www.

  • http://example.com
  • http://www.example.com
  • https://example.com
  • https://www.example.com

Click the gear in the top right and select Site Settings

Choose your preferred domain and click Save

If the preferred domain has changed, resubmit your sitemap in Search Console and Fetch as Google to crawl and index all pages of your site.

Set a preferred domain in Google Analytics

In Google Analytics, select your website property. Go to Admin (gear icon – bottom of left sidebar nav) and Property Settings

Set the Default URL and Save

Set a preferred domain in .htaccess (options for www vs non-www redirects)

Change the http in the domain  (not HTTP_HOST) to https if you’re using an SSL.

Redirect www to non-www (generic/any domain)


1
2
3
4
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Redirect www to non-www (specific to domain)


1
2
3
4
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

Redirect non-www to www (generic/any domain)


1
2
3
4
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Redirect non-www to www (specific to domain)


1
2
3
4
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

Search & Replace URLs

To avoid serving mixed content from HTTP and HTTPs urls, which can cause the security padlock in your browser to be broken, use the Better Search Replace plugin to update your urls in the database.


1
2
3
4
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

Be sure to make a backup of the database before AND do a dry run before you update. You’ll want to update the GUIDs for this type of update.