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
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">';
}
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.