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

robots.txt for website hosted in a subdirectory

· 52CE 我爱测

I have 2 website which is hosted in a shared hosting. 1st website example.com hosted in a root directory as /public_html/ 2nd website example2.com hosted in a sub-directory directory as /public_html/example_2/ I have this in exam…

问题原文

原帖链接 · Raunak Gupta · CC BY-SA 3.0

I have 2 website which is hosted in a shared hosting.
1st website
example.com hosted in a root directory as /public_html/

2nd website
example2.com hosted in a sub-directory directory as /public_html/example_2/

I have this in example.com/robots.txt

User-agent: *
Disallow: /example_2/
sitemap: https://www.example.com/sitemap.xml

I have this in example2.com/robots.txt

User-agent: *
sitemap: https://www.example2.com/sitemap.xml

I want google to index both the website separately but do not mixed each another, what I know is if a website is submitted then google scrap whole directory, except the Disallow one; So if I Disallow: /example_2/ will it effect example2.com. If so then what is the best way to write robots.txt for 2 website.

I'll be very great-full if some one can show me the right path.

已采纳解答

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

It appears that for cPanel, and perhaps others, certainly to be expected with web hosts these days, while creating a second or third web site or even a sub-domain, cPanel in order to save on setting file permissions, creates any additional site within the web space of the first site created. This may be a result of the old Apache schema using httpd.conf and compatibility. Who knows? The result is that there is confusion and potential problems that can arise.

/public_html/ is the original sites web space for example.com

/public_html/example_2/ is the second site for example2.com

For example.com, the directory directive within the configuration file points to /public_html/ and for example2.com, the directory directive within the configuration file points to /public_html/example_2/.

These are local directories on your file system and not how things are seen from the web.

What is put into /public_html/ such as index.html will be seen as example.com/index.html and what is put into /public_html/example_2/ such as index.html will be seen as example2.com/index.html.

The same will be true for robots.txt and any .htaccess file you choose to create. Example.com robots.txt would go into /public_html/ and example2.com robots.txt would go into /public_html/example_2/.

The drawback to this configuration is that example.com/example_2/index.html will show the sites home page for example2.com/index.html. This is generally not a problem. Just something to remember.

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

资料来源与适用范围

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

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

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