angularjs - 用于 SEO 配置的 .htaccess 重定向

标签 angularjs .htaccess seo

我有一个基于 angularJs 的组合,谷歌爬虫为类似平台提供了一个 URI 工具。将 #! 替换为 ?_escaped_fragment_=,您可以使用服务器重定向更改目录以提供静态文件。

我不使用 #! 所以 ?_escaped_fragment_= 将被插入到最后。我喜欢做的是制作这个图案:

www.mywebsite.com/?_escaped_fragment_=
www.mywebsite.com/page/?_escaped_fragment_=
www.mywebsite.com/page/5?_escaped_fragment_=

重定向到

www.mywebsite.com/snapshot
www.mywebsite.com/snapshot/page/
www.mywebsite.com/snapshot/page/5

这是我使用的 .htaccess 文件:

RewriteEngine On  
  RewriteCond %{QUERY_STRING} ^_escaped_fragment_=$
  RewriteRule ^$ /snapshot/
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
  RewriteRule ^ -  [L]
  RewriteRule ^ /index.html

问题是它只适用于基本 URL (index.html)。 有什么我想念的吗? 谢谢。

最佳答案

你必须像这样使用转义片段:

http://yourangularwebsite.com/?_escaped_fragment_=/page/5

然后在您的 .htaccess 中重定向它:

RewriteCond %{QUERY_STRING} _escaped_fragment_=/([^&]*)
RewriteRule ^$ /snapshot/%1 [R,L]

这会将您重定向到 http://yourangularwebsite.com/snapshot/page/5?_escaped_fragment_=/page/5

关于angularjs - 用于 SEO 配置的 .htaccess 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35819462/

相关文章:

angularjs - Ionic/Angular JS - 从反向地理定位中获取特定值

javascript - 无法使用 angularJS 将 URL 加载到 iframe

apache - .htaccess seo 友好 url 未找到问题

php - $_GET URL 来自 ?url=http ://google. com

validation - AngularJS ng-value bool 验证

javascript - 转换 document.getElementById 以访问 TypeScript 中的文件

php - 将所有请求重定向到非 www ssl https

html - SEO 页面标题的最大长度是多少?

url - 使用 web.config 从 Windows 主机帐户的 URL 中删除 php 扩展

html - 大规模重定向 xyz.html/to xyz.html