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
Advertisement
Answer
You can use strpos()
function for that:
<?php $url = $_SERVER['REQUEST_URI']; if (strpos($url,'?') !== false) { echo '<meta name="robots" content="noindex, follow" />' . "n"; } ?>