2

I'm using an angular.js app to fetch content via an external API. All works great, except for metadata and opengraph values. As we can't rewrite all metadata, we decided to use some redirection to send crawler on specific pages with metadata. We use this method : https://github.com/michaelbromley/angular-social-demo All seems to work, but when we need to get "route" params from .htaccess file, we don't have anything. We can send FB crawler on specific page, but without information.

Here is our .htaccess :

RewriteCond %{HTTP_USER_AGENT} (facebookexternalhit/[0-9]|Twitterbot|Pinterest|Google.*snippet)
RewriteRule the-page-with-angular-app.html(.*)$ http://www.oursite.net/some/directory/static-page.php?id=$1 [P]

Here is our URL :

http://www.oursite.net/the-page-with-angular-app.html#/someInfo/3437/46

Please note that our angular.js app need "#" in URL (for some reasons we can't use html5mode).

We want redirect to page : oursite.net/some/directory/static-page.php?id=someInfo/3437/46 at least, even if it could be better to redirect to oursite.net/some/directory/static-page.php?id1=someInfo&id2=3437&id3=46

For the moment, we just can redirect to oursite.net/some/directory/static-page.php (we can pass GET id if we force it in .htaccess). The rewrite cond works great.

Thanks for help,

  • 1
    My experience with angular routes with a '#' and .htaccess redirects is that they do not work right... – DrCord Oct 13 '14 at 16:47
  • Let me be a little more specific. I don't want redirect "normal" users in angular app, I want keep crawler out to redirect them in a php script wich only return a few information (such as meta, open graph meta, twitter card, etc.). I need to keep some variables to do so. I can redirect, but I loose variables for the moment. – François Soulard Oct 14 '14 at 06:46

1 Answers1

0

We apply another method to succeed.

We build a custom share URL in angular.js application (like ourdomain.com/one-folder/to-static.php?id1=somme&id2=stuff)

We use those URLs to share content within socials networks (FB, Twitter, etc.). We build our custom to-static.php to handle meta data (twitter card, open graph, etc.).

We can use .htaccess to redirect "normal" user from "to-static.php" script from our angular.js deep link. Something like this (but i don't use that):

RewriteCond %{HTTP_USER_AGENT} !(facebookexternalhit/[0-9]|Twitterbot|Pinterest|Google.*snippet)
RewriteRule static.php?id1=(.*)&id2=(.*)$ http://www.oursite.net/the-page-with-angular-app.html#/$1/$2 [P]

I decide to make tests in PHP script and redirect "normal" user with PHP method (I use this piece of code to detect crawler) : https://stackoverflow.com/a/20949242/2207250

We finally don't use .htaccess method because with ours clients installations (same angular.js app on 50th websites : joomla site, wordpress site, custom site, mobile app, etc.) it was tricky to ask for modifying htaccess file (not impossible, but if we can do other way, it's better).

Community
  • 1
  • 1