我遵循以下指南:
以角度表示:
$locationProvider.html5Mode(true);
在 html 中,添加此元标头:
<head>
<meta name="fragment" content="!">
</head>
配置阿帕奇:
RewriteEngine On
# If requested resource exists as a file or directory
# (REQUEST_FILENAME is only relative in virtualhost context, so not usable)
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
# Go to it as is
RewriteRule ^ - [L]
# If non existent
# If path ends with / and is not just a single /, redirect to without the trailing /
RewriteCond %{REQUEST_URI} ^.*/$
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)/$ $1 [R,QSA,L]
# Handle Prerender.io
RequestHeader set X-Prerender-Token "YOUR_TOKEN"
RewriteCond %{HTTP_USER_AGENT} baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest [NC,OR]
RewriteCond %{QUERY_STRING} _escaped_fragment_
# Proxy the request
RewriteRule ^(.*)$ http://service.prerender.io/http://%{HTTP_HOST}$1 [P,L]
# If non existent
# Accept everything on index.html
RewriteRule ^ /index.html
现在我的索引网站终于被谷歌收录了。
然而,每当我尝试访问我的子网站时,它都会告诉我它已被重定向到index.html
谁能告诉我我做错了什么吗?我已经尝试了几个星期,但一直无法找到解决方案:(
From google-bot-simulator
:
您正在使用 Googlebot 测试您的网站,但该用户代理不在您的重写规则正在查找的可能用户代理列表中。
RewriteCond %{HTTP_USER_AGENT} baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest [NC,OR]
上面列出了将代理到 prerender.io 的所有机器人。更具体地说,它仅列出了足以检测它们的用户代理部分。如果您添加了“googlebot”,那么它也会匹配。或者只是出于测试目的而使用“机器人”。
RewriteCond %{HTTP_USER_AGENT} bot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest [NC,OR]
试一试。另外,看看您的浏览器是否有“用户代理切换器”插件,它可以让您比通过谷歌工具更快地进行测试。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)