Disallow and Allow directives

  1. Disallow
  2. Allow
  3. Combining directives
  4. Allow and Disallow directives without parameters
  5. Using the special characters * and $
  6. Examples of how directives are interpreted

Disallow

Use this directive to prohibit indexing site sections or individual pages. For example:
  • Pages that contain confidential data.
  • Pages with site search results.
  • Site traffic statistics.
  • Duplicate pages.
  • Various logs.
  • Database service pages.

Examples:

User-agent: Yandex
Disallow: / # Prohibits crawling the entire site

User-agent: Yandex
Disallow: /catalogue # Prohibits crawling the pages that start with /catalogue

User-agent: Yandex
Disallow: /page? # Prohibits crawling the pages with a URL that contains parameters

Allow

This directive allows indexing site sections or individual pages.

Examples:

User-agent: Yandex
Allow: /cgi-bin
Disallow: /
# prohibits downloading anything except for the pages
# starting with '/cgi-bin'
User-agent: Yandex
Allow: /file.xml
# Allows downloading the file.xml file
Note. Empty line breaks aren't allowed between the User-agent, Disallow and Allow directives.

Combining directives

The Allow and Disallow directives from the corresponding User-agent block are sorted according to URL prefix length (from shortest to longest) and applied in order. If several directives match a particular site page, the robot selects the last one in the sorted list. This way the order of directives in the robots.txt file doesn't affect the way they are used by the robot.

Note. If there is a conflict between two directives with prefixes of the same length, the Allow directive takes precedence.
# Original robots.txt:
User-agent: Yandex
Allow: /
Allow: /catalog/auto
Disallow: /catalog

# Sorted robots.txt:
User-agent: Yandex
Allow: /
Disallow: /catalog
Allow: /catalog/auto
# Prohibits downloading pages that start with '/catalog',
# But allows downloading pages that start with '/catalog/auto'.

Common example:

User-agent: Yandex
Allow: /archive
Disallow: /
# allows everything that contains '/archive'; the rest is prohibited

User-agent: Yandex
Allow: /obsolete/private/*.html$ # allows HTML files
                                 # in the '/obsolete/private/... path'
Disallow: /*.php$  # probibits all '*.php' on site
Disallow: /*/private/ # prohibits all subpaths containing
                      # '/private/', but the Allow above negates
                      # part of the prohibition
Disallow: /*/old/*.zip$ # prohibits all '*.zip' files containing
                        # '/old/' in the path

User-agent: Yandex
Disallow: /add.php?*user= 
# prohibits all 'add.php?' scripts with the ' user ' option

Allow and Disallow directives without parameters

If directives don't contain parameters, the robot handles the data as follows:

User-agent: Yandex
Disallow: # same as Allow: /

User-agent: Yandex
Allow: # isn't taken into account by the robot

Using the special characters * and $

You can use the special characters * and $ to set regular expressions when specifying paths for the Allow and Disallow directives.

The * character indicates any sequence of characters (or none). Examples:

User-agent: Yandex
Disallow: /cgi-bin/*.aspx # prohibits '/cgi-bin/example.aspx' 
                          # and '/cgi-bin/private/test.aspx'
Disallow: /*private # prohibits both '/private',
                    # and '/cgi-bin/private'

By default, the * character is appended to the end of every rule described in the robots.txt file. Example:

User-agent: Yandex
Disallow: /cgi-bin* # blocks access to pages
                    # starting with '/cgi-bin'
Disallow: /cgi-bin # the same

To cancel * at the end of the rule, use the $ character, for example:

User-agent: Yandex
Disallow: /example$ # prohibits '/example',
                    # but allows '/example.html'
User-agent: Yandex
Disallow: /example # prohibits both '/example',
                   # and '/example.html'

The $ character doesn't forbid the * at the end, that is:

User-agent: Yandex
Disallow: /example$  # prohibits only '/example'
Disallow: /example*$ # exactly the same as ' Disallow: /example'
                     # prohibits both /example.html and /example

Examples of how directives are interpreted

User-agent: Yandex 
Allow: /
Disallow: /
# Everything is allowed.

User-agent: Yandex 
Allow: /$
Disallow: /
# Everything, except for the main page, is disallowed.

User-agent: Yandex
Disallow: /private*html
# '/private*html', 
# '/private/test.html' a'/private/html/test.aspx' и т. п.

User-agent: Yandex
Disallow: /private$
# Only '/private' is disallowed.

User-agent: *
Disallow: /
User-agent: Yandex
Allow: /
# As the Yandex robot 
# selects entries that have 'User-agent:' string, 
# the result is — everything is allowed.