【发布时间】:2014-12-08 07:08:20
【问题描述】:
我正在使用 angular.js 应用程序通过外部 API 获取内容。一切都很好,除了元数据和 opengraph 值。 由于我们无法重写所有元数据,我们决定使用一些重定向来在带有元数据的特定页面上发送爬虫。我们使用这种方法:https://github.com/michaelbromley/angular-social-demo 一切似乎都有效,但是当我们需要从 .htaccess 文件中获取“路由”参数时,我们什么都没有。我们可以在特定页面发送FB爬虫,但没有信息。
这是我们的 .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]
这是我们的网址:
http://www.oursite.net/the-page-with-angular-app.html#/someInfo/3437/46
请注意,我们的 angular.js 应用在 URL 中需要“#”(由于某些原因我们不能使用 html5mode)。
我们希望至少重定向到页面:oursite.net/some/directory/static-page.php?id=someInfo/3437/46,即使重定向到oursite.net/some/directory/会更好static-page.php?id1=someInfo&id2=3437&id3=46
目前,我们可以重定向到 oursite.net/some/directory/static-page.php(如果我们在 .htaccess 中强制它,我们可以传递 GET id)。重写条件效果很好。
感谢您的帮助,
【问题讨论】:
-
我对带有 '#' 和 .htaccess 重定向的角度路由的经验是它们无法正常工作......
-
让我更具体一点。我不想在 Angular 应用程序中重定向“普通”用户,我希望让爬虫在 php 脚本中重定向他们,只返回一些信息(例如元、开放图元、推特卡等)。我需要保留一些变量才能这样做。我可以重定向,但我暂时失去了变量。
标签: javascript php angularjs .htaccess redirect