http headers - How can you redirect a user on page load and still have Twitter cards work -


I am integrating into my website, especially app installs and deep linking. To do this, I added the required meta tag in the header section of my HTML page.

This feature in my app that shares articles from other websites on Twitter, to share a website URL that is not in my domain but in order to show the Twitter card, I have a simple The short URL that gets posted on my html page for that Twitter with Meta Tags and then redirected to the original site, but I'm not getting the desired result.

First , I tried to redirect the user back by returning 301 response codes in the header. It redirects the user just as I want (the browser keeps my redirect page outside of history), but the meta tag is not picked by Twitter, so the card is not visible.

Next , I tried to use a meta tag under the Twitter card meta tag like this:

  & lt; Meta http-equivalent = "fresh" content = "0; url = http: //www.mywebsite.com" & gt;  

The Twitter card appears properly with this method, but now the back button is enabled in the browser. Apart from this, I have read that this method has not been advised because security engines remove sites due to security reasons.

Does anyone know how to redirect the user without the back button can the browser be enabled and still the Meta tag can be evaluated? I like a method of doing this without using javascript.

I found this issue in an interesting way around

I only need the Twitter meta tag, when watching Twitter on my site. Therefore, when a user or bot requests on my website (which is to make Twitter to populate card information from Meta tags) I check the user agent who requested that if it was a Twitter bot (its User agent is currently twitterbot / 1.0) then i send back the page with 200 feedback codes and a meta tag redirect (in case only) in my headersOtherwise, I return with a 302 response code and the browser redirects there immediately to your use.

This is the solution to the problems of the engine after it does not favor your site with back button issue and search meta tag redirects (

UPDATE

recently Someone told me that I asked for more information about how I did this, so I thought I would provide an example. I was using C # for my server, but the code is quite easy to understand Are you using a different language .

  /// & lt; summary & gt; /// redirects the user to a location related to the given ID /// & lt; / summary & gt; // / & Lt; param name = "id" & gt; & lt; / param & gt; public ActionResult Index (Int32 ID) {// Short link IDs retrieve details about the passage (DataEntities reference = new DataEntities ()} {shortlink shortlink = context.ShortLinks.Single (s =>; s.Id == ID); // If the user agent is a Twitter bot (currently TwitterBot / 1.0), then Meta Redirect (case only In) Return date page, so Twitter can now read the meta tag. If included (Request.UserAgent.ToString () .toLower () ("twitterbot")) {TwitterCardModel Model = New TwitterCardModel {id = id, site = "@YOUR_TWITTER_HANDLE", title = shortLink.Title, description = shortLink. Description, RedirectUrl = shortLink.FullUrl, ImageUrl = shortLink.ImageUrl}; See Return (Model); } // Otherwise, redirect the user to the original page. reaction. Redirect (shortLink.FullUrl, true); Return tap; }}  

If the request was from a Twitter bot, then it was the HTML I was returned:

   @ * Twitter Card * @ & lt; Meta name = "Twitter: card" content = "summary" /> & Lt; Meta name = "Twitter: site" content = "@ model. Site" & gt; & Lt; Meta name = "Twitter: title" content = "@model.actite" /> & Lt; Meta name = "Twitter: Details" content = "@model.de description" /> @if {& lt; Meta name = "Twitter: Image" (String.IsNullOrEmpty (Model.ImageUrl)!) Content = "@ Model.ImageUrl" & gt; } & Lt; Meta name = "twitter: app: name: iphone" content = "your APP name" /> & Lt; Meta name = "Twitter: App: id: iPhone" content = "your Apple API id" /> & Lt; Meta name = "Twitter: app: url: iphone" content = "redirect your content to your content in your deep link" /> @ * redirect page full article * @ & lt; Meta http-equiv = "Refresh" content = "0; URL =@Model.RedirectUrl" & gt; & Lt; Title & gt; & Lt; / Title & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; / Body & gt;  


Comments