Jump to content

No Index Page Based on Contents of URL


leslieg

Recommended Posts

Hi,

 

I really have no idea what I am doing when it comes to php, any help is very gratefully accepted.

 

I am trying to set an out put of noindex, follow on pages when the URL contains /10-pages/

 

I have tried the following, but doesn't work and also the one below.  I am using Joomla, but I don't know if that matters.

 

<?php if (preg_match(‘\pages\‘, $_SERVER[php_SELF])) { echo <META NAME="ROBOTS" CONTENT="NOINDEX, FOLLOW"> } ?>

 

<? if (preg_match(‘/page-10/‘, $_SERVER[‘REQUEST_URI’])) { ?>put your meta no index here<? } ?>

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/294886-no-index-page-based-on-contents-of-url/
Share on other sites

One way could be to parse the url using the PHP_URL_PATH component to extract the /10-pages/ part

Then find out if the component contains what you are looking for

if it does, add your meta tag.

<?php
$url = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$pos      = strripos($url, "/10-pages/");
if ($pos !== false) {
    echo '<META NAME="ROBOTS" CONTENT="NOINDEX, FOLLOW">';
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.