我使用Angular JS模板引擎创建了一个简单的应用程序,但当我在社交媒体中共享url时,内容没有被解析,它显示为"{{}}",所以我使用htaccess解决了这个问题。每当facebook请求我http://website.com/posts/value-1我希望它重定向到静态php文件http://website.com/static.php?id=$1,但它不是使用下面的htaccess文件重定向,有解决方案吗?
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]
我自己解决了,下面是正在工作的.htaccess代码
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]