大网数据广告活动
网站运营与故障问答

My robots.txt is showing on one line after uploading

· 52CE 我爱测

So I have a weird issue, and I'm not sure if its caused due to my error or what, but when I upload a robots.txt like below: User-Agent: * Disallow: /dev/ Disallow:/wp-admin/ Disallow:/wp-includes/ Disallow:/wp-login.php It shows …

问题原文

原帖链接 · semaj0 · CC BY-SA 3.0

So I have a weird issue, and I'm not sure if its caused due to my error or what, but when I upload a robots.txt like below:

User-Agent: *
Disallow: /dev/
Disallow:/wp-admin/
Disallow:/wp-includes/
Disallow:/wp-login.php

It shows up in Google Webmaster like below, and also if I redownload said file, it will also appear this way

User-Agent: *Disallow: /dev/Disallow:/wp-admin/Disallow:/wp-includes/Disallow:/wp-login.php

How can I correct this? Is this telling me I'm doing something wrong? Is this a whitespace issue?

已采纳解答

原帖链接 · closetnoc · CC BY-SA 3.0

Much of the time, there are two things to look at.

One is, if you are editing the file on Windows, the CR (carriage control) LF (line feed) [EOL] (end of line) marker needs to be changed to just LF for Linux. Some editors and tools allow for this with an option while others do not. Also keep in mind that there are 3rd. party tools that get in the way of the process such as management tools.

The second is how the file is transferred. Most of the time, an FTP client is used and text is not the default transfer method, however, most FTP clients will use text for a .txt file extension at least. I have had to specifically select text over binary even for obvious text files before. Most FTP clients will handle file extensions correctly. Still, sometimes the file is not converted correctly even with the best of intentions. As well, I have seen FTP servers at fault here though rarely.

Whenever you see a problem like this, check to see if the uploaded file matches the original with something like WordPad where the code can be examined. This can tell you if the file is being uploaded correctly. Many control panels will allow you to open a file transparently to properly compare the two. If the upload is not handling the [EOL] marker properly, then it is likely the transfer method. For FTP, you can always force text transfers over binary. If this still does not work, then in any control panel, you can simply upload the file. Some will make the change for you. If that still does not work use SSH (shell) and edit the file, remove the contents, then cut and paste from the original. This should always work. For smaller files, this works a treat. For larger files, it can be frustratingly slow but should work fine as well.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2016-08-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。