0

We have a multi-store setup with more than 10 stores (different languages and domains), which share many products between them.

The problem:

If we want to do a product promotion on say - Instagram, and include a product URL in the description, it would only be one store (obviously, its dumb to direct a Spanish customer to a Danish site), so:

How to create a "universal" URL which will automatically redirect the customer to the correct store (based on location and language).

Note: Our sites do have hreflang with alternate hrefs set up.

EDIT

Our store is based on Magento framework. My current idea:
1)Have a URL with a parameter of a product ID.
2)This URL directs to a PHP file in which I receive the parameter, by which I can get the product data, then I can loop through the available alternate hrefs (from database).
3)I get the user locale and language (Im not very sure how to do this).
4)Check if any of the available hreflang matches this user and direct them to it.

Metal Mathematician
  • 388
  • 1
  • 3
  • 15
  • Make a page (whether serverside or clientside) that will detect the location, choose appropriate language (with a sane default), and redirect to the appropriate page. Which step do you have problems with? Also, are you always just redirecting to the same top page (in different languages), or do you want the ability to redirect to e.g. specific articles or news announcements? – Amadan Oct 16 '18 at 07:20
  • @Amadan Im looking for a way to make this flexible so I could give a link to any product and it would automatically choose the correct URL from the `alternate` ones (like google uses it when you search for an item). – Metal Mathematician Oct 16 '18 at 07:25
  • That implies the customer has loaded a specific localised page (say, Spanish), and you want to bump him over to his presumably preferred page (say, Danish). In JS, it's easy (once you determine what `lang` you want): `window.location = document.querySelector('a[rel="alternate"][hreflang|="' + lang + '"]').getAttribute('href')`. However, as a customer, I would hate that - if I get the Spanish link, I want to read the Spanish page, even in Denmark. The "universal page" idea that redirects to the preferred language is definitely better. Don't look at the links; you need the DB that has them. – Amadan Oct 16 '18 at 07:34
  • @Amadan Thanks for your help! My vision was that there could be a way to, once the URL is clicked some API goes through the `alternate hrefs` of that page and sends you to the "best" one for you. – Metal Mathematician Oct 16 '18 at 07:38
  • So I guess in the URL to my "universal page" I could be providing the ID of my item and then go through the `alternate hrefs` of that product ID, then direct them to the best one, though I am not sure if this is feasable to be honest – Metal Mathematician Oct 16 '18 at 07:40
  • Ideally, you shouldn't _have_ a page, really. The simple idea is - have a serverside script that gets the page ID, inspects the request, matches the [`Accept-Language` header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language) with the available languages, and serves a [307 Temporary Redirect](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/307) to the appropriate URL. Parsing `Accept-Language` is non-trivial, but you haven't stated what language your backend is in... You could do almost the same thing with JS (with what I have above), but serverside is better. – Amadan Oct 16 '18 at 07:42
  • Interesting, I will look into this, this is the sort of idea I was looking for, but I am just wondering if this hasnt been made into an "easy-to-use" web app or smiliar – Metal Mathematician Oct 16 '18 at 07:45
  • If you do do it serverside, you'd (hopefully) go through your database, not through the alternate links already present on some page. Again, no details on your architecture, or URL patterns, so I can only talk in generalities. "I am not sure if this is feasable to be honest" - same here, if you don't specify _why_ you have doubts about the feasibility, they cannot be addressed. All of this is actually pretty easy, no need for an "easy-to-use" web app - which is why my first question was where, specifically, do you see a problem. Just do it. :) – Amadan Oct 16 '18 at 07:46
  • Thank you so much, my first positive experience on stackoverflow, you got me thinking and I think I know how to solve it. If you want to move your ideas from comments to an answer, I will definitely accept it, given how little info I provided (which you made me realise), I didnt deserve such a great response. – Metal Mathematician Oct 16 '18 at 07:54
  • Still not too late to improve your question. At least edit and tag with your serverside language and/or framework. :) – Amadan Oct 16 '18 at 07:56
  • Check my edited question, I added my current idea, see if you can spot something I'm not aware of – Metal Mathematician Oct 16 '18 at 08:11

1 Answers1

1

As you synthesised in your update:

  • Have an URL with a product ID parameter
  • In a PHP file, receive the parameter, and retrieve all available languages from the database for that ID
  • use the Accept-Language header to see which of the languages is the best fit for the user. Pick English if none match, because default world language, yada yada. Using the PHP HTTP_ACCEPT_LANGUAGE server variable has several implementations of a function that does this.
  • Serve a page with 302 Found status, and Location header that points to the localised URL. It may be good to also include the body with all the metadata (I'm not expert in SEO, and not 100% sure what Google will or won't look at and/or remember when it encounters a 302).
Amadan
  • 191,408
  • 23
  • 240
  • 301
  • 1
    Since you mentioned location in your OP, note that `Accept-Language` doesn't care about location (which I think is a great thing). This way, if a Swedish person with Swedish Windows (but "can also read Norwegian and English" set in regional settings) on a business trip to Tokyo won't be served the Japanese page. – Amadan Oct 16 '18 at 08:51
  • Thing is, we have a store in Italian for customers in Italy and another store in Italian for customers in Switzerland, since the items we can deliver is different from country to country, hence why location is beneficial. – Metal Mathematician Oct 16 '18 at 08:58
  • Hmm. I don't know what operating systems of Italian Swiss households are set to: `it`, `it-CH` or `it-IT`. If their computers actually know they're Swiss, you have no problem, as they'll send `it-CH` to you, which you can react to. If their owners just say "We're Italians", you'll likely get `it-IT`. The best way to combat this is probably setting a session variable (assuming the EU Cookie Law doesn't eat you) to remember which language the user wants; so if they switch from the default one, use that one instead of repeating the language detection the next time they land on the bounce page. – Amadan Oct 16 '18 at 09:07