Can some translate these PHP lines into Perl?
Thanks in advance,PHP Code:<?php
if (strstr($_SERVER['REQUEST_URI'], '?') || strstr($_SERVER['REQUEST_URI'], '&'))
{
header('X-Robots-Tag: noindex,noarchive,nosnippet');
}
?>
John
Can some translate these PHP lines into Perl?
Thanks in advance,PHP Code:<?php
if (strstr($_SERVER['REQUEST_URI'], '?') || strstr($_SERVER['REQUEST_URI'], '&'))
{
header('X-Robots-Tag: noindex,noarchive,nosnippet');
}
?>
John
Haven't tested, but the following would probably be a good start if you're primarily concerned with preventing pages with GET variables from appearing in search results:
... or ...Code:if ( "" != $ENV['QUERY_STRING'] ) { print "X-Robots-Tag: noindex,noarchive,nosnippet"; }
Code:use CGI; $q = new CGI; @q_param = $q->url_param; if ( $#q_param != -1 ) { print "X-Robots-Tag: noindex,noarchive,nosnippet"; }
Dan LeFree | Owner/Operator (Web development, marketing)
Dan I am not sure if you got my point.
I want to block URLs including a "?" and "&".
The code samples should have caught any requests which included a query string (which seemed to be a more elegant implementation - best to avoid substring comparisons if possible). Tested both and they definitely didn't work as intended...
Try:
(Tested and confirmed working)Code:if ( $ENV{'REQUEST_URI'} =~ m/\&/ || $ENV{'REQUEST_URI'} =~ m/\?/ ) { print "X-Robots-Tag: noindex,noarchive,nosnippet"; }
Update: ... and here's a working implementation of the CGI GET parameter count if it will be sufficient to simply determine whether GET variables have been set:
Code:use CGI; $q = new CGI; if ( $q->url_param > 0 ) { print "X-Robots-Tag: noindex,noarchive,nosnippet"; }
Dan LeFree | Owner/Operator (Web development, marketing)
Thank you very much Dan. I will try those out!![]()