What is hreflang?
hreflang is a tag attribute tells google search engine which language you are using on a specific page and serve results based on the searcher’s country and language preferences.
Code Sample:
<link rel=”alternate” href=”http://example.com” hreflang=”fr” />
<link rel=”alternate” href=”http://example.com/fr/” hreflang=”Nl” />
Where the Hreflang Attribute Goes?
- using link elements in the – HTML hreflang link elements in your <head>
- using HTTP headers – The second method of implementing hreflang is through HTTP headers. HTTP headers are for all your PDFs and other non-HTML content you might want to optimize.
- or using an XML sitemap -The third option to implement hreflang is using XML sitemap markup. It uses the xhtml:link attribute in XML sitemaps to add the annotation to every URL.
Very common issue, we unaware about it:
– If we are not following trailing slash it will create hreflang conflict error when you analysis your website SEO.
Ex: https://example.com/about and
https://example.com/about/
Both URL’s are looking the same but we missed trailing slash on first one. So we should use trailing slash in all url to avoid hreflang conflict issue.
Ex: https://example.com/about/ and
https://www.example.com/about/
Both links are looking the same, but we missed www. on first one. So we should add www in all url to avoid hreflang conflict issue.
Above two hreflang conflict issues fixed by using .htaccess file as like as follows
# Basic WordPress RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # Force https RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] #Force www RewriteCond %{HTTP_HOST} !^www.quadrus.be$ [NC] RewriteRule ^(.*)$ https://www.quadrus.be/$1 [L,R=301]