谷歌页面速度:避免登录页面重定向?

时间:2013-04-17 作者:Desi

我从Google PageSpeed收到以下通知:

Avoid landing page redirects

To speed up page load times for visitors of your site, remove as many landing page redirections as possible, and make any required redirections cacheable if possible.

http://site.com/blog is a non-cacheable redirect to http://site.com/blog/
我的html文件中没有尾部斜杠,所以我不知道为什么blog 重定向到blog/. 实际页面在此处。如何更正此问题?

1 个回复
最合适的回答,由SO网友:s_ha_dum 整理而成

最浪费的重定向之一经常发生,web开发人员通常没有意识到这一点。如果URL缺少尾随斜杠(/),则会发生这种情况,否则应该有一个。例如,转到http://astrology.yahoo.com/astrology 导致301响应,其中包含重定向到http://astrology.yahoo.com/astrology/ (请注意添加的尾部斜杠)。在Apache中,通过使用Alias或mod\\u rewrite或DirectorySlash指令(如果您使用的是Apache处理程序)可以修复此问题。

http://developer.yahoo.com/performance/rules.html

你应该fix this by adding the trailing slash 连接到你的链接,而不是试图通过与服务器抗争来加载无斜杠的URL。正如前面引用中所暗示的,您可以更改Apache的DirectorySlash 指令,但。。。

通常,如果用户请求的资源没有尾部斜杠,而尾部斜杠指向目录,mod\\u dir会将其重定向到同一资源,但有一些很好的理由使用尾部斜杠:

用户最终请求资源mod\\u autoindex正常工作的规范URL。由于它不发出链接中的路径,因此它将指向错误的路径

http://httpd.apache.org/docs/current/mod/mod_dir.html#directoryslash

... 你可能不想这样。

我不知道你的HTML是如何生成的,但可以推测,由于这是一个WordPress网站,它是由插件或主题模板文件生成的。编辑这些应该很容易,但如果没有更多的代码,我只能猜测。

结束

相关推荐

使用`auth_reDirect`:即使我已经登录,也一直要求我登录

我正在尝试使用auth_redirect 在访问特定页面时自动重定向未登录的访问者。以下是我使用的代码:add_action(\'template_redirect\',\'wpse16975_check_if_logged_in\'); function wpse16975_check_if_logged_in(){ $pageid = 29; if(is_page($pageid)) auth_redirect(); } 重定向工作正常(我看到