【问题标题】:Error getting .htaccess to direct googlebot using _escaped_fragment_使用 _escaped_fragment_ 获取 .htaccess 以直接访问 googlebot 时出错
【发布时间】:2023-03-08 15:03:01
【问题描述】:

我正在尝试使用我的主干应用程序的预呈现服务将我的页面在谷歌上编入索引。

我知道当我专门将 googlebot 添加到用户代理列表时设置工作正常,但有人建议我不要这样做,而是使用 _escaped_fragment_ 方法。唯一的问题是 _escaped_fragment_ 参数没有正确传递。可以帮忙吗?

谢谢!!!

    # html5 pushstate (history) support:

<ifModule mod_rewrite.c>

    RewriteEngine On

    RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
    RewriteCond %{HTTPS} !on
    RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L] 

# 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 "xxxxxxxx"

    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_

# Proxy the request
    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/https://www.example.com/$2 [P,L]

  # If non existent

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !index
    RewriteRule (.*) index.html [L,QSA]


</ifModule>

所有 apache 模块都已加载并正在工作。

【问题讨论】:

  • 您是否在html标头或链接中添加了&lt;meta name="fragment" content="!"&gt;代码?
  • 您尝试使用预渲染服务显示的页面不是真实文件? (因为向前你用 -f 排除了真实文件)

标签: regex apache .htaccess seo


【解决方案1】:

所以.htaccess 实际上是正确的......这里是谷歌的官方答案。

引用约翰·穆勒(Google 员工)http://productforums.google.com/forum/#!category-topic/webmasters/crawling-indexing--ranking/bZgWCJTnl08%5B1-25%5D 的内容

Looking at your blog's homepage, one thing to keep in mind is that the Fetch
as Googlebot feature does not parse the content that it fetches. So when you
submit toddmoyer.net/blog/ , it fetches that URL. After fetching the URL, it
doesn't parse it to check for the "fragment" meta tag, it just returns it to
you. However, if you fetch toddmoyer.net/blog/#! , then it should rewrite the
URL and fetch the URL toddmoyer.net/blog/?_escaped_fragment_= .

When we crawl and index your pages, we'll notice the meta-tag and act
accordingly. It's just the Fetch as Googlebot feature that doesn't check for
meta-tags, and instead just returns the raw content.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-11
    • 2023-03-28
    • 2023-03-16
    • 1970-01-01
    • 2012-11-03
    • 2015-08-28
    • 1970-01-01
    相关资源
    最近更新 更多