How to write disallow paths for comments when their urls keep on changing

Muhammad butt asked:

I want to disallow pages that develop after someone comments on my post. For example, recently I got a comment (number 12) on my post page and a new page was formed with URL:

Now if another person comments (number 13) on my post then I am expecting a page URL like:

So my question is what should I put in my robots.txt disallow path to avoid google index my post pages that are developing after comments.

Currently, the path I have given in my robots.txt file to restrain google from indexing my comment files with different number is as follow:

Disallow: /*#comment-

By this directive, I mean google shouldn’t index any url related to my website that includes #comment-

I am not sure whether I am right or not please assist me in disallowing my comments.

Allah Bless You.

My answer:

There is only one web page here. The hash and text beyond it are a named anchor, which points to a specific location on that page. If you click one it will load the page /post/ and then scroll down to comment 12 or 13 or whichever one you clicked.

Search engines will just load the whole page. They are smart enough to not try to load a named anchor as if it were a separate page. (However, note that there are a couple of old web frameworks that abused the anchor to create actual separate "pages" in a single-page app. This approach has been largely abandoned due to the variety of problems it caused, but your site doesn’t appear to be one of these.)

You don’t need to do anything in robots.txt.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.