qtranslate-slug
qtranslate-slug copied to clipboard
QTS hreflang rewrite causes error for main page
My site was not being picked up for multilingual setup so I have now been researching a bit and it seems that QTS is part of the problems.
If I have QTS disable, the href settings are:
<link
hreflang="fi" href="https://dokkcopy.demo.site/fi/" rel="alternate" />
<link
hreflang="en" href="https://dokkcopy.demo.site/en/" rel="alternate" />
<link
hreflang="x-default" href="https://dokkcopy.demo.site/" rel="alternate" />
The English link is OK but the Finnish one (default) should be https://dokkcopy.demo.site
Now activating QTS, I get
<link
hreflang="x-default" href="https://dokkcopy.demo.site" rel="alternate" />
<link
hreflang="fi" href="https://dokkcopy.demo.site" rel="alternate" />
<link
hreflang="en" href="https://dokkcopy.demo.site/en" rel="alternate" />
Now the default link is good, but the english link is missing the trailing "/" and this causes an error as the server does a 301 on the URL without the slash and the hreflang test fails.
I did a temporary brute force fix in class-qtranslate-slug.php (I know that I only have /en to fix):
if (substr(esc_url($this->get_current_url($language)), -3) == "/en") { echo '<link hreflang="'.$language.'" href="'.esc_url($this->get_current_url($language)).'/" rel="alternate" />'."\n"; } else { echo '<link hreflang="'.$language.'" href="'.esc_url($this->get_current_url($language)).'" rel="alternate" />'."\n"; }
Hi @The3IC , thanks for the report. I've made few changes to the hreflang on the latest branch. I'll look into this as well.