I've stumbled upon a tricky situation I'm not sure how to solve.
I use the Facebook Graph API to track shares on my web app's articles and display that counter to my users. The API requires that I specify an og:url property to know under which URL to aggregate counts.
My URL structure is as follows:
.../posts/id/slug
The slug is purely cosmetic and optional. If it is later changed (which sometimes happens), I want to ensure:
- That my users are still redirected to the right page
- That the share counter isn't reset
To satisfy condition 1, I set up the following redirects:
A) .../posts/id --> .../posts/id/current-slug
B) .../posts/id/wrong-slug --> .../posts/id/current-slug
To satisfy condition 2, I pointed my og:url to the slugless URL .../posts/id, which is invariable.
But of course, this causes a redirect loop for the Facebook grapher, whether the initial URL was correct (case X) or not (case Y).
Case X:
Start: .../posts/id/slug
--> .../posts/id (Because of og:url)
--> .../posts/id/slug (Because of redirect)
--> (loop)
Case Y:
Start: .../posts/id/wrong-slug
--> .../posts/id/correct-slug (Because of redirect)
--> (back to case 1)
Any idea how to solve that problem?
The only solution I see at the moment is to remove redirect A), but it makes the URL much less user/SEO friendly.
Aucun commentaire:
Enregistrer un commentaire