Jump to content


Photo
- - - - -

google indexing empty url variable


  • Please log in to reply
4 replies to this topic

#1 darren

darren

    Likes Etomite Forums!

  • Member
  • PipPip
  • 251 posts

Posted 27 May 2008 - 11:05 PM

anyone know a way to block indexing of a page with an empty url variable?

ie google indexes ".index.php?id="

can't seem to find how to block this. I read adding a '$' in robots.txt (Disallow: /index.php?id=$) would do it but tested it at GWC and the page is still allowed.

Etomite does a good job of redirecting to the home page when there is an empty variable, but in a site with lots of variables, not managed with Etomite, you get a messed up blank page from these links (from google). Just another reason why i should use etomite for every website i program from this point forward..... ;)

#2 -Ed-

-Ed-

    Likes Etomite Forums!

  • Developers
  • PipPip
  • 220 posts

Posted 28 May 2008 - 08:50 AM

anyone know a way to block indexing of a page with an empty url variable?

ie google indexes ".index.php?id="

can't seem to find how to block this. I read adding a '$' in robots.txt (Disallow: /index.php?id=$) would do it but tested it at GWC and the page is still allowed.

Etomite does a good job of redirecting to the home page when there is an empty variable, but in a site with lots of variables, not managed with Etomite, you get a messed up blank page from these links (from google). Just another reason why i should use etomite for every website i program from this point forward..... ;)

Hi darren,

First solution is indeed using Etomite to do it for you :P

Secondly, I've been working on a site prior to Etomite, and was using the following code for the id pages:

$page = $_GET['id']; 
if ($page =="") {header("Location: /");
}
If you include this to the top of the page displayed, or include it on every page in your site,
it will always go to the root of the site if "id" is empty.



You could also use:
$page = $_GET['id']; 
if ($page =="") {header("Location: ?id=index");
}
if you want "home" to always be www.mysite.com/index.php?id=index


Hope this helps.

Edited by Ed Headset, 28 May 2008 - 08:50 AM.


#3 darren

darren

    Likes Etomite Forums!

  • Member
  • PipPip
  • 251 posts

Posted 28 May 2008 - 04:09 PM

$2 = $_GET['2']; if ($2 =="") {header("Location: /"); }
else
$3 = $_GET['3']; if ($3 =="") {header("Location: /"); }
else
$4 = $_GET['4']; if ($4 =="") {header("Location: /"); }

;) this runs circles around modifying a robots file... Thanks Ed!

I can even check certain variables depending on what page youre on!
[codebox]/* get url */
$currentFile = $_SERVER["SCRIPT_NAME"];
/* remove folder structure */
$parts = Explode('/', $currentFile);
$page = $parts[count($parts) - 1];
/* define possible variables */
$ONE = $_GET['1'];
$TWO = $_GET['2'];
$THREE = $_GET['3'];
$FOUR = $_GET['4'];
/* run through page scenarios, checking for empty url variables and booting you home if necessary */
if ($page == "pageone.php" )
{
if ($TWO =="") {header("Location: /"); }
else
if ($THREE =="") {header("Location: /"); }
}

if ($page == "pagetwo.php" )
{
if ($ONE =="") {header("Location: /"); }
else
if ($FOUR =="") {header("Location: /"); }
} ...[/codebox]

:D sorry, i have to share my exitement as no-one in my office cares right now. :Party:

Edited by darren, 28 May 2008 - 05:51 PM.


#4 -Ed-

-Ed-

    Likes Etomite Forums!

  • Developers
  • PipPip
  • 220 posts

Posted 02 June 2008 - 08:29 AM

;) this runs circles around modifying a robots file... Thanks Ed!
:D sorry, i have to share my exitement as no-one in my office cares right now. :Party:


No problem mate,

It's nice to hear it works :lol:

#5 Zandery

Zandery

    Etomite Forum Newbie

  • Member
  • 1 posts

Posted 09 February 2012 - 02:12 PM

This is certainly easier than having to keep changing my robots text file for pages that I don't want indexed. Thanks.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users