duanemei2194 2016-01-08 21:38
浏览 73
已采纳

无法重定向facebook http用户代理的URL

I created simple application using Angular JS template engine but when I share the url in social media contents are not parsed it shows '{{}}' so I worked around using htaccess. whenever facebook requests my http://website.com/posts/value-1 I want it to redirect to static php file at http://website.com/static.php?id=$1 but it is not redirecting using the below htaccess file , Any Solutions ?

RewriteEngine on
  # If an existing asset or directory is requested go to it as it is
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
  RewriteRule ^ - [L]

  # If the requested resource doesn't exist, use index.html
  RewriteRule ^ /pages/index.html
  Redirect /index.html http://website.com/home/

  RewriteCond %{HTTP_USER_AGENT} (facebookexternalhit/[0-9](+http://www.facebook.com/externalhit_uatext.php)|Twitterbot|Pinterest|facebot/[0-9]|Google.*snippet)
  RewriteRule ^posts/(.*)$ http://www.website.com/static.php?id=$1 [NC,L]
  • 写回答

1条回答 默认 最新

  • douyi5961 2016-01-13 03:27
    关注

    I Solved it myself below is the working .htaccess code

    RewriteEngine on
      # If an existing asset or directory is requested go to it as it is
      RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
      RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
      RewriteRule ^ - [L]
    
      # If the requested resource doesn't exist, use index.html
      RewriteRule ^ /pages/index.html
      Redirect /index.html http://website.com/home/
    
      RewriteCond %{HTTP_USER_AGENT} (facebookexternalhit/[0-9](+http://www.facebook.com/externalhit_uatext.php)|Twitterbot|Pinterest|facebot/[0-9]|Google.*snippet)
      RewriteRule ^(posts)/(.*)$ http://www.website.com/static.php?id=$1 [NC,L]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部