6

web-app ディレクトリにある静的ファイル sitemap.xml と robots.txt をマップしたいと考えています。URL は次のようになります。

http://www.mydomain.com/sitemap.xml 
http://www.mydomain.com/robots.txt

これらのルートを機能させるには、どのように URL マッピングを設定する必要がありますか?

4

3 に答える 3

10

The simplest way is to tell grails to ignore them in UrlMappings.groovy:

class UrlMappings {
    static excludes = ['/robots.txt', '/sitemap.xml']

    static mappings = {
        // normal mappings here ...
    }
}
于 2013-07-31T21:49:38.493 に答える
8

このマッピングを次の目的で使用しますrobots.txt

"/robots.txt" (view: "/robots")

そしてgrails-app/views/robots.gsp、 のコンテンツを含む を用意しrobots.txtます。このように<g:if env="...">して、環境ごとに異なるコンテンツを簡単に作成できます。

これを「.xml」拡張子で機能させるには、コンテンツ ネゴシエーションの構成を変更する必要があります。

grails.mime.file.extensions = false // disables the parsing of file extensions from URLs into the request format
于 2013-07-31T14:47:18.870 に答える
0

ステージング環境を使用している場合は、ステージング環境に nofollow を設定することも役立つ場合があります。ステージング サイトをインデックス化するユース ケースがあるかどうかはわかりません.... 同意する場合は、これらの手順を使用してそれをブロックできる場合があります。

Tomcat を使用している場合は、NOFOLLOW=trueなどの環境変数を設定します--> 例を参照してください: TOMCAT_OPTS、環境変数、および System.getEnv()

次に@doelleriが述べたように、urlMappingsを設定します

UrlMappings

//Robots.txt
"/robots.txt"(controller: 'robots', action:'robots')

次に、robotsController を使用して、ステージング Tomcat で設定した環境変数を検出します。

ロボットコントローラー

def robots() {
    if (System.getenv('NOFOLLOW') == 'true') {
        def text = "User-agent: *\n" +
            "Disallow: /cgi-bin/ \n" +
            "Disallow: /tmp/ \n" +
            "Disallow: /junk/ \n" +
            "Disallow: /admin/ \n" +
            "Crawl-delay: 5 \n" +
            "Sitemap: https://www.example.com/sitemap.xml"

        render(text: text, contentType: "text/plain", encoding: "UTF-8")
    } else {
        render(status: 404, text: 'Failed to load robots.txt')
    }
}

robots.gsp

<%-- Content rendered from controller -> so leave blank :) --%> 
于 2015-12-07T19:17:51.010 に答える