I am using Gallery 2.3 with URL Rewrite enabled. Google Image Search finds only thumbnails from my site. Is it possible to disallow thumbnails for Googlebot-Image in robots.txt and allow only larger versions of images?
All size image URLs are very similar, like:
/d/57791-4/image.jpg
I would like to have different urls for thumbnails like:
/thumb/57791-4/image.jpg
Is it possible to do it with URL Rewrite only?
Posts: 16503
Not as is. You'd either have to hack core files and reapply those updates after every upgrade or I think you could hack something like that in a theme and .htaccess without having to modify core files, but it could mean more maintenance in the future. See below for a rough working model of this. Visit my site today only to see an example (the top image is the "/thumb/path/to/image.jpg" thumbnail)
This is just a rough sketch.
http://codex.gallery2.org/Gallery2:Editing_Templates
album.tpl edit:
<img src="/thumb/{$child.thumbnail.id}-{$child.thumbnail.serialNumber}/{$child.pathComponent}NOTE: that, as is only works for thumbnails of images and not thumbnails of albums. You'd need to write a little bit more logic to check if the item can contain children and at a ".jpg" to the end of the pathComponent. Of course I'm also assuming that the album highlight is always a jpg and that it's always going to be ".jpg" and not ".JPG" or ".jpeg" or ."JPEG or any other sort of combination let alone a .gif or .png.
.htaccess edit, add this rule to .htaccess
RewriteCond %{THE_REQUEST} /thumb/([0-9]+)-([0-9]+)/([^/?]+)(\?.|\ .) RewriteCond %{REQUEST_URI} !/main\.php$ RewriteRule . /main.php?g2_view=core.DownloadItem&g2_itemId=%1&g2_serialNumber=%2&g2_fileName=%3 [QSA,L]I'm no rewrite rule expert, but I'm pretty sure you'll either need to duplicate some of the current rewrite rules to another section of .htaccess that Gallery doesn't write to when you make changes in Site Admin > URL Rewrite or you'll have to reapply those changes every time you modify URL Rewrite if you add those 2 conditions and rule to the existing set of rewrite rules.
I'll leave my site up like this for a day, visit my site and you'll see double thumbnails of any image. I even added in logic to handle album thumbnails and image frames:
Here's my edits to album.tpl My additions are in red I would remove, for a production site, what I've highlighted in green
{if isset($theme.params.$frameType) && isset($child.thumbnail)} {g->container type="imageframe.ImageFrame" frame=$theme.params.$frameType width=$child.thumbnail.width height=$child.thumbnail.height} <a href="{$linkUrl}"> {if ($child.canContainChildren || $child.entityType == 'GalleryLinkItem')} <img id="%ID%" src="/thumb/{$child.thumbnail.id}-{$child.thumbnail.serialNumber}/{$child.pathComponent}.jpg"> {else} <img id="%ID%" src="/thumb/{$child.thumbnail.id}-{$child.thumbnail.serialNumber}/{$child.pathComponent}"> {/if} {g->image id="%ID%" item=$child image=$child.thumbnail class="%CLASS% giThumbnail"} </a> {/g->container} {elseif isset($child.thumbnail)} <a href="{$linkUrl}"> {if ($child.canContainChildren || $child.entityType == 'GalleryLinkItem')} <img src="/thumb/{$child.thumbnail.id}-{$child.thumbnail.serialNumber}/{$child.pathComponent}.jpg"> {else} <img src="/thumb/{$child.thumbnail.id}-{$child.thumbnail.serialNumber}/{$child.pathComponent}"> {/if} {g->image item=$child image=$child.thumbnail class="giThumbnail"} </a> {else} <a href="{$linkUrl}" class="giMissingThumbnail"> {g->text text="no thumbnail"} </a> {/if}Even tested with Image Frames.
Edit: Then of course edit your robots.txt file.
NOTE: this is at theme level so if you change themes, while nothing should break, google will be able to index those images again if you don't apply these changes to the theme you are using.
I made those changes to the Matrix (default) theme.
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here
Posts: 2
Your instructions very precise, everything works at my site as should, I have checked with Google Webmasters Tools "Analyze robots.txt".
Posts: 16503
It didn't start out that way
I was just going to write 2 or 3 quick sentences with a code snippet, but it turned into a fun exercise.
Glad it worked. I'll be removing those changes from my site now (in case anyone else is watching this thread and wondering why they are not seeing what I've described above)
I don't know if it is the ideal solution, I'm pretty sure it's not, but it works. You may need to make changes to this if there are ever major changes to the template engine for Gallery.
I got the smarty variable information from setting Gallery into debug mode:
FAQ: How to set/use Gallery in debug mode?
Once Gallery is in debug mode a Smarty Debug pop-up window will appear.
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here
Posts: 18
nivekiam,
Could you please explain how to apply this to thumbs of albums that have subalbums and to random images in Image Block?
===
Visit my Photo Art Album
Posts: 16503
About the Image Block, I don't have a clue. I'll have to play around with that on my server, I could have sworn with URL Rewrite enabled that on my install Image Block used the short, pretty named URLs.
As for the album/subalbum thing can you post a link to a specific album where you are seeing this?
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here
Posts: 215
It doesn't appear to work when you have spaces in the image filename from when I tried it.
_________
Mark
Posts: 16503
Don't put spaces in file names ;)
As a general rule of thumb I never put spaces in filenames, underscores, dashes or CamelCase are what I use, it sure makes life a lot easier and breaks a lot less things.
But can you post a link where you see this?
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here
Posts: 215
Most of my images uses this.
http://www.markridgwell.co.uk/v/ByDate/2009/2009-03-08+Cressing+Temple+Barn/Mike+Simmons+Falconry/
With the above change this was generating http://www.markridgwell.co.uk/thumbnail/95423/2/Bald Eagle Flying 01.jpg
adding int the |escape:"url" to the end of the $child.PathComponent changed it to:
http://www.markridgwell.co.uk/thumbnail/95423/2/Bald%20Eagle%20Flying%2001.jpg
The better url should be:
http://www.markridgwell.co.uk/thumbnail/95423/2/Bald+Eagle+Flying+01.jpg
as that would match the original:
http://www.markridgwell.co.uk/images/95423/2/Bald+Eagle+Flying+01.jpg
I have investigated an alternative way of doing this that fits in slightly better with how G2 works, but that has involved modifying several files and a manual edit to my .htaccess. Which means that its more of a nightmare if any of these files get changed
I've changed the GalleryDerivativeImage.class to generate a different URL if its a thumbnail, but haven't yet worked out how to link it up to effectively call core.DownloadItem (I called mine core.DownloadThumbnailItem) without the edit to .htaccess:
core/classes/GalleryDerivativeImage.class:
/** * @see GalleryDerivative::render */ function render($format, $item, $params) { global $gallery; switch($format) { case 'HTML': $urlGenerator =& $gallery->getUrlGenerator(); if( $this->derivativeType == DERIVATIVE_TYPE_IMAGE_THUMBNAIL ) { $src = $urlGenerator->generateUrl( array('view' => 'core.DownloadThumbnailItem', 'itemId' => $this->getId(), 'serialNumber' => $this->getSerialNumber()), array('forceFullUrl' => !empty($params['forceFullUrl']))); } else { $src = $urlGenerator->generateUrl( array('view' => 'core.DownloadItem', 'itemId' => $this->getId(), 'serialNumber' => $this->getSerialNumber()), array('forceFullUrl' => !empty($params['forceFullUrl']))); } // ....I've also added this to rewrite/module.inc:
/* Rule 1: Thumb Download Item */ $rules[6] = array( 'comment' => $this->translate('Thumbnail Download Item'), 'match' => array('view' => 'core.DownloadThumbnailItem'), 'pattern' => 'thumbnail/%itemId%-%serialNumber%/%fileName%', 'keywords' => array( 'serialNumber' => array( 'pattern' => '([0-9]+)', 'help' => $this->translate( 'Ensures browsers do not use cached version when image has changed'), 'function' => array('rewrite', 'RewriteSimpleHelper', 'parseSerialNumber')), 'fileName' => array( 'pattern' => '([^/?]+)', 'help' => $this->translate('The item file name.'), 'function' => array('rewrite', 'RewriteSimpleHelper', 'parseFileName'))), 'help' => $this->translate('The general URL for downloading items.'));After enabling the rewrite rule I added the following lines to the top of my .htaccess:
# Add special case for thumbnails as /thumbnail RewriteCond %{THE_REQUEST} /thumbnail/([0-9]+)-([0-9]+)/([^/?]+)(\?.|\ .) RewriteCond %{REQUEST_URI} !/main\.php$ RewriteRule . /main.php?g2_view=core.DownloadItem&g2_itemId=%1&g2_serialNumber=%2&g2_fileName=%3 [QSA,L]Ideally I'd like to just enable the rewrite rule and it to do everything without this manual change or have it isolated in a local .tpl file
Any ideas?
_________
Mark
Posts: 16503
My idea is to dump the use of spaces and use dashes or underscores in file and folder (album) names. ;) IMO, spaces in file and directory names are just a bad idea even more so on anything web related.
I'm not going to spend any time trying to figure out a way to hack or code around the use of spaces.
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here
Posts: 18
Ok, I found a way to have /thumbs in the image path for ImageBlock items too. Find the proper place in ImageBlock.tpl and replace the green code with the red one. NOTE: My g2 has gone through a lot of hacking, so in your code things might look a bit different. Anyway the idea is the same as with thumbs in albums. (Everything is ok with subalbums) ;)
{if isset($ImageBlockData.$frameType)} {g->container type="imageframe.ImageFrame" frame=$ImageBlockData.$frameType width=$block.thumb.width height=$block.thumb.height maxSize=$maxSize} {$link} <img id="%ID%" src="/thumb/{$block.thumb.id}-{$block.thumb.serialNumber}/{$imageItem.pathComponent}" class="{"%CLASS%"}" /> {g->image item=$imageItem image=$block.thumb id="%ID%" class="%CLASS%" maxSize=$maxSize forceFullUrl=$ImageBlockData.forceFullUrl } {if !empty($linkHref)} {**** Some more code goes here... ***} {else} {$link} <img src="/thumb/{$block.thumb.id}-{$block.thumb.serialNumber}/{$imageItem.pathComponent}" class="{"giThumbnail"}" /> {g->image item=$imageItem image=$block.thumb class="giThumbnail" maxSize=$maxSize forceFullUrl=$ImageBlockData.forceFullUrl }===
Visit my Photo Art Album