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
- 还是应用程序结构的“根”李>
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