2014-07-18 64 views
0

環境在OpenShift的Python 2.7/Bottle應用程序中放置robots.txt文件的位置?

  • 的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
  • 或應用程序結構的「根」?

編輯:

爲了澄清,所述應用程序是一個Bottle應用程序,以便有一個數字,提供不同的內容的路由。

此外,所有頁面都通過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應放置,使其送達正確。

回答

2

解決方案

這似乎已經奏效用戶UNOR的回答告知具體的解決方案。

添加瓶子路線Python應用程序:

@route('/robots.txt') 
def serve_robots(): 
    return static_file('robots.txt', root='app-root/repo/wsgi/static/') 

,然後添加到robots.txtwsgi/static/

然後robots.txt文件可以訪問。

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

將robots.txt文件放在後端的位置並不重要。
它只能從Web訪問robots.txt。

對於每個主機,該文件必須在/robots.txt處可用。所以它必須始終在主機的根目錄中,而不是在一個子文件夾中。

例子:

當一個機器人要抓取http://example.com/wsgi/static/file_1.txt,它應該對http://example.com/robots.txt一個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

相關問題