Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 在OpenShift上的Python 2.7/Bottle应用程序中,在何处放置robots.txt文件?_Python 2.7_Openshift_Robots.txt_Bottle - Fatal编程技术网

Python 2.7 在OpenShift上的Python 2.7/Bottle应用程序中,在何处放置robots.txt文件?

Python 2.7 在OpenShift上的Python 2.7/Bottle应用程序中,在何处放置robots.txt文件?,python-2.7,openshift,robots.txt,bottle,Python 2.7,Openshift,Robots.txt,Bottle,环境 Python 2.7 OpenShift 应用程序结构: .git .openshift data libs wsgi - static - views - application - my_bottle_app.py README.md setup.py setup.pyc setup.pyo 期望的行为 我想为以下位置的文件创建robots.txt规则: wsgi/static/file_1.txt wsgi/static/file_2.txt 例如: User-age

环境

  • Python 2.7
  • OpenShift
应用程序结构:

.git
.openshift
data
libs
wsgi
 - static
 - views
 - application
 - my_bottle_app.py
README.md
setup.py
setup.pyc
setup.pyo
期望的行为

我想为以下位置的文件创建
robots.txt
规则:

wsgi/static/file_1.txt
wsgi/static/file_2.txt
例如:

User-agent: *
Disallow: /file_1.txt
Disallow: /file_2.txt
问题

robots.txt
文件是否应放在

  • wsgi
  • wsgi/static
  • 还是应用程序结构的“根”
编辑:

为了澄清这一点,该应用程序是一个应用程序,因此有许多路由服务于不同的内容

此外,所有页面都通过带有自定义功能的https提供:

def redirect_http_to_https(callback):
    '''Bottle plugin that redirects all http requests to https'''

    def wrapper(*args, **kwargs):
    scheme = request.urlparts[0]
    if scheme == 'http':
        # request is http; redirect to https
        redirect(request.url.replace('http', 'https', 1))
    else:
        # request is already https; okay to proceed
        return callback(*args, **kwargs)
    return wrapper

install(redirect_http_to_https)

因此,我试图理解应该将
robots.txt
放置在哪里,以便正确地提供服务

将robots.txt文件放在后端的何处并不重要。
它只关系到从Web访问robots.txt的位置

对于每台主机,文件必须位于
/robots.txt
。因此,它必须始终位于主机的根目录中,而不是子文件夹中

示例:

当机器人想要爬网时
http://example.com/wsgi/static/file_1.txt
,它应该在
http://example.com/robots.txt

如果是
https://example.com/wsgi/static/file_1.txt
(https而不是http),位置必须是
https://example.com/robots.txt


如果是
http://www.example.com/wsgi/static/file_1.txt
(带子域),位置必须是
http://www.example.com/robots.txt

将robots.txt文件放在后端的何处并不重要。
它只关系到从Web访问robots.txt的位置

对于每台主机,文件必须位于
/robots.txt
。因此,它必须始终位于主机的根目录中,而不是子文件夹中

示例:

当机器人想要爬网时
http://example.com/wsgi/static/file_1.txt
,它应该在
http://example.com/robots.txt

如果是
https://example.com/wsgi/static/file_1.txt
(https而不是http),位置必须是
https://example.com/robots.txt


如果是
http://www.example.com/wsgi/static/file_1.txt
(带子域),位置必须是
http://www.example.com/robots.txt

解决方案

这是用户unor的回答所告知的似乎有效的具体解决方案

在Python应用程序中添加瓶子路线:

@route('/robots.txt')
def serve_robots():
    return static_file('robots.txt', root='app-root/repo/wsgi/static/')
然后将
robots.txt
添加到
wsgi/static/

然后,可以在以下位置访问
robots.txt
文件

https://app-username.rhcloud.com/robots.tx

解决方案

这是用户unor的回答所告知的似乎有效的具体解决方案

在Python应用程序中添加瓶子路线:

@route('/robots.txt')
def serve_robots():
    return static_file('robots.txt', root='app-root/repo/wsgi/static/')
然后将
robots.txt
添加到
wsgi/static/

然后,可以在以下位置访问
robots.txt
文件

https://app-username.rhcloud.com/robots.tx