3

I recently started a WordPress blog with HTTPS and want some advice.

I prefer to use HTTPS + www for my blog. In order to do that will I have to add all these 4 types of addresses to Webmaster Tools?

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

If yes, to what specific URL do I need to submit the sitemap.xml file to? Does the same go with XML file also? Do I need to submit all XML files to each domain separately or just to one?

Redirect code in .htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
</IfModule>
2

Yes, you have to add the all 4 variants of links.

In this case you prefer this version https://www.example.com so adding the sitemap to the preferred version will be enough.

2

I prefer to use https + www for my blog.

Presumably you have already set up a canonical 301 redirect to https://www.example.com?

will I have to add all these 4 types of addresses to webmaster tools?

Yes, this is recommended. It then allows you to set the preferred domain (www vs non-www) and to check for any errors (eg. a non-canonical getting indexed etc.).

to what specific URL do I need to submit the sitemap.xml file with?

The canonical property. ie. https://www.example.com.

Does the same goes with xml file also?

What (additional?) XML file?

Do I need to submit all xml files to each domain separately or just a one?

Once you've added all properties to Google Search Console (formerly Google Webmaster Tools) then you concentrate just on the canonical property. You can periodically check the other properties to make sure there are no errors etc.

UPDATE:

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

This code is not sufficient. This is a 302 (temporary) redirect from HTTP to HTTPS only. It will not redirect the non-canonical https://example.com (ie. non-www to www). You would need something like the following:

RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.example.com/$1 [R=301,L]

All requests that are either port 80 (ie. not HTTPS) or are not www then redirect to the canonical URL. You need to explicitly include the 301 status with the R flag, otherwise it defaults to a 302. (But it is a good idea to test first with a 302 to make sure it's working, since this won't be cached.) You also don't need the <IfModule> wrapper.

  • I have added these lines in my .htaccess file <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.example.com/$1 [R,L] </IfModule> if that's the 301 redirect. Is there any problem with this bunch of code? – Anjana Nilupul Jan 2 '17 at 11:35
  • That code is not sufficient. I've updated my answer. – MrWhite Jan 2 '17 at 11:56
  • 1
    Wow! Thanks. Sharing is caring. I will do and check whether it's working. Thanks again – Anjana Nilupul Jan 2 '17 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.