2016-03-23 11 views
1

私はtxt応答を提供するlaravelを使用して動的ルートを作成しました。Googlebotが動的robots.txtを認識しない

ブラウザで動作しますが、googlebotにはrobots.txtというファイルはありません。

これは私が取得ヘッダーです:これは私の私のlaravelルートである

Cache-Control →no-cache Connection →keep-alive Content-Disposition →inline; filename="robots.txt" Content-Encoding →gzip Content-Type →text/plain; charset=UTF-8 Date →Wed, 23 Mar 2016 11:36:44 GMT Server →nginx/1.9.12 Transfer-Encoding →chunked Vary →Accept-Encoding

Route::get('robots.txt', '[email protected]');

そして、これはメソッドです:

public function robots(){ return response()->view('txt.robots')->header('Content-Type', 'text/plain')->header('Content-Disposition', 'inline; filename="robots.txt"'); }

私はContent-Disposition →attachment; filename="robots.txt"を試しましたが、Googleではrobots.txtというファイルがないと言っています。

は私が

これは私のnginxの構成である(これは、ブラウザ上で動作します)Googleウェブマスターツールから動作しませContent-Dispositionや静止画を削除しようとしました、多分ここで間違って何かがあります`` `

server { 
listen 80 default_server; 
listen [::]:80 default_server; 
server_name mydomain.com; 
root /home/forge/mydomain.com/public; 

# FORGE SSL (DO NOT REMOVE!) 
# ssl_certificate; 
# ssl_certificate_key; 

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 

index index.html index.htm index.php; 

charset utf-8; 



location/{ 
    try_files $uri $uri/ /index.php?$query_string; 
} 

location = /favicon.ico { access_log off; log_not_found off; } 
#location = /robots.txt { access_log off; log_not_found off; } 

#location = /robots.txt { 
# try_files $uri $uri/ /index.php?$args; 
# access_log off; 
# log_not_found off; 
#} 

access_log off; 
error_log /var/log/nginx/mydomain.com-error.log error; 

error_page 404 /index.php; 

location ~ \.php$ { 
    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    fastcgi_pass unix:/var/run/php5-fpm.sock; 
    fastcgi_index index.php; 
    include fastcgi_params; 
} 

location ~ /\.ht { 
    deny all; 
} 


# Expire rules for static content 

# cache.appcache, your document html and data 
location ~* \.(?:manifest|appcache|html?|xml|json)$ { 
    expires -1; 
    # access_log logs/static.log; # I don't usually include a static log 
} 

# Feed 
location ~* \.(?:rss|atom)$ { 
    expires 1h; 
    add_header Cache-Control "public"; 
} 

# Media: images, icons, video, audio, HTC 
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ { 
    expires 1M; 
    access_log off; 
    add_header Cache-Control "public"; 
} 

# CSS, Javascript and Fonts 
location ~* \.(?:css|js|woff|ttf|eot)$ { 
    expires 1y; 
    access_log off; 
    add_header Cache-Control "public"; 
} 
} 
``` 

ありがとう。

+0

'Content-Disposition'、 'inline;を削除してください。ヘッダーから。 –

答えて

0

私はContent-lengthヘッダーを追加して解決しました。コード結果は次のとおりです。

$response = response()->view('txt.robots')->header('Content-Type', 'text/plain'); 
    $response->header('Content-Length',strlen($response->getOriginalContent())); 

    return $response; 

これが役立つことを望みます。あなたの回答に感謝します。

1

私はhttp://www.google.com/robots.txt HTTPレスポンスヘッダを検査し、次のとおりです。

Cache-Control:private, max-age=0 
Content-Encoding:gzip 
Content-Length:1574 
Content-Type:text/plain 
Date:Wed, 23 Mar 2016 12:07:44 GMT 
Expires:Wed, 23 Mar 2016 12:07:44 GMT 
Last-Modified:Fri, 04 Mar 2016 19:02:51 GMT 
Server:sffe 
Vary:Accept-Encoding 
X-Content-Type-Options:nosniff 
X-XSS-Protection:1; mode=block 

なぜContent-Type:text/plainヘッダとContent-Dispositionヘッダだけ出力テキストをスキップしていませんか?

も...

  • はあなたのrobots.txtのURLが外の世界から入手可能ですか?たぶんプロキシを使用して二重チェックを行うことがあります。
  • 出力UTF-8はエンコードされていますか?

+0

私はContent-Dispositionを動作させようとしている間に追加しました。私の元のコードはただ1つのヘッダー(テキスト/プレーン)を持っていました /robotsにアクセスできます。txtを外部から問題なく使用することができ、ヘッダ 'Content-Type:text/plain;のためutf-8であるはずです。 charset = UTF-8' – rogervila

0

Content-Dispositionヘッダは、ブラウザでファイルのダウンロードを強制するために使用されている詳細はhttps://developers.google.com/webmasters/control-crawl-index/docs/robots_txtを参照してください。それはおそらく、Googleのボットにファイルを与えないと混乱させます。

public function robots(){ 
    return response()->view('txt.robots')->header('Content-Type', 'text/plain'); 
} 
+0

これは私のオリジナルコードですが、Googleでは動作しません。応答は正しいですが、Googleのウェブマスターツールにはrobots.txtファイルがないと書かれています – rogervila

+0

ブラウザからアクセスできますか?また、 'robots.txt'の内容は重要です。ファイル自体へのアクセスを有効にする必要があります。 –

+0

はい、あなたはブラウザでアクセスでき、その内容を検証しました。 問題は静的ファイルではなく、text/plainヘッダーを持つサーバー応答です。私は自分のnginxの設定をチェックして、それも動作します。 – rogervila

関連する問題