Embedded UrlGenerator and rewrite problems

kiz_0987

Joined: 2005-02-27
Posts: 189
Posted: Thu, 2006-03-16 17:38

I have some issues with using clean_urls (in Drupal4.7) and URL rewrite (in Gallery2.1 cvs).

When clean_urls are not used the embedUri is /testsite/drupal?q=gallery (everything works). When clean_urls are used the embedUri becomes /testsite/drupal/gallery/ - so the full parameters passed to init are:

Array
(
    [embedUri] => /testsite/drupal/gallery/
    [g2Uri] => /testsite/gallery2/
    [loginRedirect] => /testsite/drupal/user/login
    [activeUserId] => 1
    [activeLanguage] => 
    [fullInit] => 1
)

This then gives a warning (but everything seems to work) when G2 URL rewrite is stopped (by deselecting all rules):

Warning: strpos(): Empty delimiter. in /XXX/public_html/testsite/gallery2/modules/core/classes/GalleryUrlGenerator.class on line 812

If the trailing slash is removed from embedUri the warning is not generated. Which is the correct embedUri? (note that GalleryDiscoveryUtilities puts the trailing slash in).

With clean_urls in Drupal and G2 URL rewrite active (rule = gallery/%path%) with embedUri = '/testsite/drupal/gallery/' the thumbnails have paths such as

/testsite/drupal/gallery/gallery/album2/DSCN2884.JPG.html

Note the 2 gallery parts. This causes none of the images to be visible.

If I change embedUri to remove the trailing slash (/testsite/drupal/gallery) it still does not work, as now URLs are generated with other path info (relative). For example when I'm at http://www.example.com/testsite/drupal/admin/settings/gallery the images in the sideblock have urls like http://www.example.com/testsite/drupal/admin/settings/gallery/album1/DSCN2954.JPG.html as in the source they are listed as
<a href="gallery/album1/DSCN2954.JPG.html" >

Any help would be really appreciated. Thanks.

Gallery version = 2.1-rc-2a core 1.0.34
PHP version = 4.3.11 cgi
Webserver = Apache/1.3.34 (Unix) mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 FrontPage/5.0.2.2635 mod_ssl/2.8.25 OpenSSL/0.9.7g PHP-CGI/0.1b
Database = mysql 4.1.18-standard, lock.system=flock
Toolkits = ArchiveUpload, Exif, Getid3, Thumbnail, Gd, ImageMagick, Ffmpeg
Acceleration = none, none
Operating system = Linux server1.hostingplex.com 2.4.31 #1 SMP Fri Jun 3 12:08:30 EDT 2005 i686
Default theme = matrix
Locale = en_US
Browser = Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6 
 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Sat, 2006-03-18 09:14

please get the latest drupal integration code from cvs. it should have some docs for drupa / g2 rewrites.

 
kiz_0987

Joined: 2005-02-27
Posts: 189
Posted: Sat, 2006-03-18 11:25

Thanks valiant, but I should have been clearer. I am writing a new version of the drupal gallery.module (a major update to my enhanced gallery.module from http://drupal.org/node/35379 ) so it's not a matter of using the latest cvs version. Walkah and I have been in touch about this, but he has no time to spend on the module. The url rewrite rules suggested for drupal/G2 are as I described above.

I think the simple question is whether $embedUri = /testsite/drupal/gallery/ should be valid for G2.1 embed code. If it should be then GalleryUrlGenerator.class has a bug. If it's not valid then I still need to figure out a way for URL rewrite to turn http://www.example.com/testsite/drupal/gallery?g2_itemId=31 into http://www.example.com/testsite/drupal/gallery/testphoto. Not easy as URL rewrite uses a relative path (see above for issues).

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Sun, 2006-03-19 06:06

signe has updated the drupal module 4 days ago or so.
please at least take a look at his changes.

i have no clue about drupal and its rewrite stuff. can't help you there.

currently fixing the initNavigation() bug. this embedUri should be ok. but i'd also assume, that g2.1 rc-2 automatically sets the file part to "index.php" if you don't specify it, unless you set embedUri to /foo/bar/| (not the trailing "|" ). it's fixed in cvs in a few minutes.
thanks for reporting. :)

 
kiz_0987

Joined: 2005-02-27
Posts: 189
Posted: Sun, 2006-03-19 18:54

Thanks for the fix valiant. No more warnings now occur, but it still does not work with URL rewrite using embedUri = /testsite/drupal/gallery/ or embedUri =/testsite/drupal/gallery/|

Note that your G2EmbedDiscoveryUtilities.class validator would add an additional '/' to the latter, so I had to bypass it for the test. When I regenerate the URL rules the .htaccess file has:

    RewriteCond %{THE_REQUEST} \ /testsite/drupal/v/([^?]+)(\?.|\ .)
    RewriteCond %{REQUEST_FILENAME} !/testsite/drupal/\|$
    RewriteRule .   /testsite/drupal/|?g2_view=core.ShowItem&g2_path=%1   [QSA,L]

No mention of the 'gallery' portion anywhere, which does not seem right to me. Presumably the URL rewrite module is not generating the rule correctly.

However, I have fixed this my case by changing the way I was defining the embedUri. Now I can use embedUri =/testsite/drupal/?q=gallery and everything will work. In this case the .htaccess file has:

    RewriteCond %{THE_REQUEST} \ /testsite/drupal/v/([^?]+)(\?.|\ .)
    RewriteCond %{REQUEST_FILENAME} !/testsite/drupal/$
    RewriteRule .   /testsite/drupal/?q=gallery&g2_view=core.ShowItem&g2_path=%1   [QSA,L]

and everything works fine.

The second reason nothing was working for me was that I misinterpreted the embedded URL rewrite help. It states "For URL Rewrite to work in an embedded environment you need to set up an extra htaccess file to hold the mod_rewrite rules." which I took to mean that the location of this extra .htaccess file was not that important. Since I didn't want it overwriting my drupal .htaccess file I put it somewhere else. It was only after checking http://codex.gallery2.org/index.php/Gallery2:Modules:rewrite I see that the extra .htaccess file really has to be the same as the drupal one. Can the help please be updated sometime to clarify this.

Thanks -- it's good to finally have this working well.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Mon, 2006-03-20 07:49

are you using the rewrite module's API?
using GalleryEmbed:: whatever won't set / change your g2 rewrite stuff by itself, you need to call the rewrite API.
the wpg2 integration does that already.

Quote:
I see that the extra .htaccess file really has to be the same as the drupal one. Can the help please be updated sometime to clarify this.

no. 2 different files. there's one in the g2 folder to handle standalone rewrites and another in your drupal dir, that is, your drupal .htaccess will have some g2 rewrite rules too.

please take a look at the drupal g2 module in cvs, it has been updated by signe. also take a look at the wpg2 module to see how to use the rewrite api to automate things once you figured out the right general config.

 
kiz_0987

Joined: 2005-02-27
Posts: 189
Posted: Mon, 2006-03-20 11:39

valiant. This is not yet using the rewrite API, but I've already checked the wpg2 stuff and will incorporate it sometime. The .htaccess snippets I provided were generated by manually configuring the URL rewrite module from the Gallery2 site admin pages (while within Drupal of course) -- ie this is the standard method that should work, but as you can see does not.

Quote:
no. 2 different files. there's one in the g2 folder to handle standalone rewrites and another in your drupal dir, that is, your drupal .htaccess will have some g2 rewrite rules too.

Exactly -- but the help on the URL rewrite config page itself just states it needs to be a different htaccess file than your Gallery2 one, not that it needs to be the same as your drupal one.

Anyway, for my purposes this is solved. By using embedUri =/testsite/drupal/?q=gallery it works very well. Much better in fact than current drupal embed code as any rewrite rule can be set (the current code only allows the view rule to be set). But in the more general case (perhaps for other integrations), although you have fixed it so that embedUri's like /foo/bar/ will not generate warnings, they will not work with URL rewrite, and so can still not be used.

I have checked the Gallery cvs code by cryptographite (Signe), but don't think it would have changed much of what I have done. BTW, I doubt many drupal people actually know about this version since the module is also stored on cvs in drupal and is the place people will look (I assume this work was done as GMC will need a new gallery.module version). The drupal cvs version has not been updated since Dec 2005 which has led to a range of patches on the drupal gallery.module issues page. I have been in touch with walkah to try to resolve this. I will contact cryptographite also.

 
light-blue

Joined: 2008-07-03
Posts: 7
Posted: Fri, 2008-07-11 18:42

For clarification, setting changes you make in Site Admin | URL Rewrite will modify (consider the following paths as a common install) not /var/www/drupal/.htaccess but /var/www/drupal/gallery2/.htaccess. Thus, there are two .htaccess files. Something strange happened on my system such that the SETUP tab in URL Rewrite settings started asking for the location of the .htaccess file. I copied the /var/www/drupal/.htaccess to /var/www/drupal/gallery2/.htaccess and changed permissions to 777 on both files, then returned to the RULES tab and re-saved. Everything worked after that.