g2_GALLERYSID fix

penfield888

Joined: 2004-03-02
Posts: 43
Posted: Sun, 2008-11-09 18:39

At least in my case, g2Image inserts URLs with a g2_GALLERYSID on them. I can't imagine any case where anyone would want this, but perhaps such a case exists. I've also seen other people wrestle with how to get rid of it.

I just took a brute force approach and got rid of any and all occurrences in the g2image code. It works for me. No guarantees that it will not break you site. I don't see any downside to this though. If your generated HTML has no g2_GALLERYSID parameters, it won't do anything.

If it does have that parameter, this code will strip it out. I have made the regex such that if there is a parameter after the SID, it deletes the & separator too, so that if getting rid of the SID makes the next param the first one, it will properly have the ? in front of it.

I'm using the Drupal gallery module with the g2Image add-on, so I'm not sure where this would appear in your file structure, but for me it's in the
/lots/of/stuff/g2image/jscripts/functions.js file.

On line 374, I added this:

Quote:
/* hack to filter g2_GALLERYSID from URL */
htmlCode = htmlCode.replace(/g2_GALLERYSID=[^&"]+&?/g, '');

So now it looks like this, in context

Quote:
/* hack to filter g2_GALLERYSID from URL */
htmlCode = htmlCode.replace(/g2_GALLERYSID=[^&"]+&?/g, '');

insertHtml(htmlCode,obj);
}

That regex still leaves a ? at the end of the URL. I might be able to figure it out with a lookahead, but the easy way is just to use two regexes and slightly more overhead. This should do it (untested). The first regex grabs any SIDs with another paramter after and puts in the correct delimiter (? or &). Then it looks to see if there are any SIDS that haven't been replaced yet because they don't have any parameter after them, and it gets rid of those.

Quote:

htmlCode = htmlCode.replace(/([\?&])g2_GALLERYSID=[^&"]+&/g, '$1');
htmlCode = htmlCode.replace(/([\?&])g2_GALLERYSID=[^&"]+/g, '');

I hope this helps. It would be nice to see it integrated into the distro (please please please) so you wouldn't have to fold it in with each upgrade.

BTW, the reason this matters is that Google and other search engines will consider different session IDs to be having different URLs. So it could think you have two or six or sixty pages, where you only have one. That's suboptimal.

Gallery 2, by default, does not serve up a g2_GALLERYSID to search engines when they crawl your site (at least it's not supposed to).

Take care.

------------------------------
Yosemite Explorer - info and virtual "tours" of Yosemite
Yosemite Photos - the part that actually uses Gallery

Login or register to post comments