I use this meta tags to make google crawler know that I have two languages for my site, as suggested here support.google.
<link rel="alternate" hreflang="x-default" href="http://www.example.com" />
<link rel="alternate" hreflang="de" href="http://www.example.com/de" />
<link rel="alternate" hreflang="en" href="http://www.example.com/en" />
So sometimes the content of example.com
would be the same as example.com/de
and sometimes example.com
would be the same as example.com/en
.
I use the following code to detect language
const lang = (
getLangFromUrl(req.url) ||
getLangFromCookies(req.cookies) ||
getLangFromHeader(req.headers) ||
'de'
);
and google detects example.com
and example.com/de
as duplicated pages.
Can you please tell me how should it be correctly done?