23

I have a few dynamic generated URLs.

Can I use regex to block these URLs in a robots.txt file?

  • It would also be worth setting robots meta tags on the pages you don't want crawled/indexed. – Andrew Lott Dec 8 '14 at 10:59
  • @AndrewLott In my case I have more then 500 page, so I thought use regex in robots.txt.. – Sudheera Njs Dec 8 '14 at 12:57
  • Then a rule in your site code is probably more helpful. – Andrew Lott Dec 8 '14 at 13:32
27

Regular Expressions are not valid in robots.txt, but Google, Bing and some other bots do recognise some pattern matching.

Say if you wanted to block all URLs that have a example any where in the URL, you can use a wild card entry *

User-agent: *
Disallow: /*example

You can also use the dollar sign $ to specify that the URLs must end that way. So if you wanted to block all URLs that end with example, but not URLs that had aexample elsewhere in the URL you could use:

User-agent: *
Disallow: /*example$

More in-depth info for Google can be found here: Robots.txt Specifications, Bing here: How to Create a Robots.txt file and there is a an interactive guide on Moz here

  • Perfect, * is working fine, Tested in web master tool.. Thanks Max...:) – Sudheera Njs Dec 8 '14 at 5:39
  • I'd caution from using too fancy directives in your robots.txt file; these are really, really hard to debug later on. Try to keep things as simple as possible. Also remember that robots.txt is case-sensitive, so you may need to add alternate versions of the directives depending on your site. – John Mueller Dec 10 '14 at 12:01
  • would be nice if regex was supported – SuperUberDuper Apr 14 '16 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.