noindex ?query urls

#525748
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Thanks for contacting us, and sorry for any inconvenience that might have been caused due to that.

    You can handle those in two ways. Either you can disallow those URLs with query parameter in your robots.txt file to prevent search engine bots to crawl them. Here’s an example on how they should look like:

    User-agent: *
    Disallow: */?query-*

    Here’s how you can edit robots.txt file using Rank Math:
    https://rankmath.com/kb/add-sitemaps-to-robots-txt/#num-2-2-navigate-to-edit-robots-txt

    Or, you may use the following filter to set noindex to those URLs with specific query parameters:

    add_filter( 'rank_math/frontend/robots', function( $robots ) {
    	$url = home_url( $_SERVER['REQUEST_URI'] );
    	if( (strpos($url,"?query-") !== false) )  {
    		$robots["index"] = 'noindex';
    		$robots["follow"] = 'nofollow';
    	}
    	return $robots;
    });

    Here’s how you can add filter/hook to your WordPress site:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Let us know how it goes. Looking forward to helping you.

    Thank you.

    Thanks a bunch.

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)

The ticket ‘noindex ?query urls’ is closed to new replies.