2016-08-20 53 views
1

我已预渲染工作并运行除根(家)页面以外的所有页面。预渲染与Anguar UI路由器不呈现根页面动态内容

例如:

http://www.example.com/?_escaped_fragment_= 

不呈现动态数据。所有其他网页就像

http://www.example.com/contact?_escaped_fragment_= 

这就像角UI路由器不知道是什么状态,它是在这么离开视图空白的根源。但是没有escaped_fragment的根页面http://www.example.com会正确显示它。

我已经在头文件中添加了片段元标记,并且在角度配置中将html5添加为了true。


的index.html:

<meta name="fragment" content="!"> 

app.js:

$locationProvider.html5Mode(true); 
$locationProvider.hashPrefix('!'); 

的.htaccess:

# Change YOUR_TOKEN to your prerender token and uncomment that line if you want to cache urls and view crawl stats 
# Change http://example.com (at the end of the last RewriteRule) to your website url 

<IfModule mod_headers.c> 
    #RequestHeader set X-Prerender-Token "MY TOKEN" 
</IfModule> 

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    <IfModule mod_proxy_http.c> 
     RewriteCond %{HTTP_USER_AGENT} baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator [NC,OR] 
     RewriteCond %{QUERY_STRING} _escaped_fragment_ 

     # Only proxy the request to Prerender if it's a request for HTML 
     RewriteRule ^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.gif|\.pdf|\.doc|\.txt|\.ico|\.rss|\.zip|\.mp3|\.rar|\.exe|\.wmv|\.doc|\.avi|\.ppt|\.mpg|\.mpeg|\.tif|\.wav|\.mov|\.psd|\.ai|\.xls|\.mp4|\.m4a|\.swf|\.dat|\.dmg|\.iso|\.flv|\.m4v|\.torrent|\.ttf|\.woff))(.*) http://service.prerender.io/http://www.example.com$2 [P,L] 
    </IfModule> 

</IfModule> 


# BEGIN WordPress 
    <IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/
    RewriteRule ^index\.php$ - [L] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule . /index.php [L] 
    </IfModule> 
# END WordPress 

回答

2

你的.htaccess可能的URL设置为/索引.php为主页。如果是这样,您可以将您的重写规则更改为:

RewriteRule ^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.gif|\.pdf|\.doc|\.txt|\.ico|\.rss|\.zip|\.mp3|\.rar|\.exe|\.wmv|\.doc|\.avi|\.ppt|\.mpg|\.mpeg|\.tif|\.wav|\.mov|\.psd|\.ai|\.xls|\.mp4|\.m4a|\.swf|\.dat|\.dmg|\.iso|\.flv|\.m4v|\.torrent|\.ttf|\.woff))(index\.php)?(.*) http://service.prerender.io/http://www.example.com$3 [P,L] 

我添加了(index.php)?如果发现并将$ 2更改为$ 3,则将其捕获。不要忘记将http://www.example.com更改为您的域名。