问题
I have followed the following guide:
In angular:
$locationProvider.html5Mode(true);
In html, add this meta header:
<head>
<meta name="fragment" content="!">
</head>
Configure Apache:
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
Now my index site is finally being picked up by google.
HOWEVER whenever i attempt to go to my subsite it tells me that it has been redirected to index.html
Can anyone please tell me what im doing wrong? i have attempted this for weeks and hasnt been able to come up with a solution :(
From google-bot-simulator
:
回答1:
You are testing your site with Googlebot, but that user agent is not in the list of possible user agents that your Rewrite rules are looking for.
RewriteCond %{HTTP_USER_AGENT} baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest [NC,OR]
The above lists all the bots that will be proxied to prerender.io. More specifically it lists just parts of the user agent that is enough to detect them. If you added 'googlebot' then it would match that as well. Or prehaps just 'bot' for testing purposes.
RewriteCond %{HTTP_USER_AGENT} bot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest [NC,OR]
Give it a try. Also, see if your browser has a 'User Agent Switcher' plugin that would let you test quicker than going through the google tools.
回答2:
What did your htaccess look like before? I think that this would be the reason why your subdomains would all be showing index.html:
# If non existent
# Accept everything on index.html
RewriteRule ^ /index.html
来源:https://stackoverflow.com/questions/32696549/prerender-io-subpages-redirect-to-index