The most popular page on my site is the main page of the Gallery2 install.
How can I prevent this? I only want people to view my photos through the Drupal site and the /gallery/ mapping.

/gallery2/main.php

Comments

dmuth’s picture

One way I could think of would be to hack the main.php page to check the referrer. Something like:

<?php

if (ststr(getenv("HTTP_REFERER"), "node") )  {
header("Location: http://yourwebsite/gallery/");
exit;
}

?>

Incidentally, that's one of the reasons I use acidfree for photos on my website. It's integrated with Drupal and I have the files being served by the filemanager module.

Good luck!

-- Doug

--
Douglas Muth, Philadelphia, PA
http://www.claws-and-paws.com/

snackmaster’s picture

Thanks! Thats what I was looking for but my redirect skills were of the endless loop variety :)

That said, the above code generates an "unexpected T_STRING" error on the header line when placed at the very top of the main.php page. I played a bit but couldn't get rid of it. Ideas?

dmuth’s picture

Yeah, there was a typo in my code.

It should read:

header("Location: http://yourwebsite/gallery/");

That's what I get for writing code when I'm tired. :-P

--
Douglas Muth, Philadelphia, PA
http://www.claws-and-paws.com/

snackmaster’s picture

Sorry to say there appears to eb another typo and once functional the behavior is quite odd (to me).

This line
if (ststr(getenv("HTTP_REFERER"), "node") )
needs to have ststr be "strstr"

Once I change that and put in my URL I'm not quite sure what to put in where you have "node" since my problem visitors aren't accessing a Node but the Gallery site directly so I put in that URL.
Once I do that the Gallery main.php page still laods but no pictures show up. Same happens on the main Drupal site.

Clueless here how to get this working.
(dmuth is mumbling, Acid Free! you moron! :)

deepak@dipak.org’s picture

I had a similiar issue. Google was mostly indexing my /gallery/ pages but it also indexed a few /gallery2/ links, which I did not want. In addition to the solution suggested earliar, I would also suggest you create a robot.txt on your main site with a similiar content:

User-agent: *
Disallow: /gallery2/

Deepak

snackmaster’s picture

From day 1 I've had the code to disallow, even before I launched the site. SE's apparently pay no heed :(

User-agent: *
Disallow: /gallery2/
Disallow: /includes/
Disallow: /misc/
Disallow: /modules/
Disallow: /scripts/
Disallow: /sites/
Disallow: /themes/

dmuth’s picture

The robots.txt file only contains "suggestions" for search engines to follow. Well behaved search engines like Google will listen to that. But a poorly behaved one (or a spambot) will not.

Furthermore, robots.txt is NOT an access control mechanism So you'll have to use some other method of preventing access to those files.

-- Doug

--
Douglas Muth, Philadelphia, PA
http://www.claws-and-paws.com/

snackmaster’s picture

Yep I'm aware of the basic uselessness of Robots.txt thanks to unscrupulous SE's but use it anyhow as a few SE's appear to actually follow the convention.

I'd like to get a programatic of server based dissallow script that protects my hot folders (redirects them to he77), is there a known list of offending engines?

kiz_0987’s picture

Gallery2 supports an "embedded only" mode defined in config.php. Change the line:
$gallery->setConfig('mode.embed.only', false); to true.
Maybe that will do what you need.

snackmaster’s picture

Awesome tip. I found the code at line 130 of my config.php file.

/*
 * Embedded mode.  You can disable direct access to main.php (standalone G2)
 * by setting this this flag to true.
 */
$gallery->setConfig('mode.embed.only', true);

I se it to "true" as above, problem is it had zero affect. I used the admin to clear the Gallery DB cache, made sure I wasn;t a logged in users etc. Tried clearing local cache and different browser but /gallery2/main.php still loaded no problem.

Thanks to all for the help, I'll keep looking!

kiz_0987’s picture

If embedded-only does not work then I suggest you raise the issue in the Gallery2 support forum.

alexandreracine’s picture

alexandreracine’s picture

Doing so works. Now, it would be great if I could add a redirection instead of showing a big ERROR message!

Anyone know how to do it?

Alexandre Racine

www.gardienvirtuel.com Sécurité informatique, conformité, consultation, etc

www.salsamontreal.com La référence salsa à Montréal

alexandreracine’s picture