set urls with parameter to noindex in wordpress?

Viewed 1088

I'm looking for a solution to set all URLs which uses the parameter '?' to noindex. I look for a php solution which I could use in the header.php in Wordpress or in the .htaccess.

I tryed this:

<?php
$url = $_SERVER['REQUEST_URI'];
if( preg_match('/\?/', $url) ) {
    echo '<meta name="robots" content="noindex, follow" />' . "\n";
}
?>

This solution did not work and URLs with the parameter '?' didn't get a noindex attribute.

Best regards

1 Answers
Related