Support » Plugin: WordPress Gallery Plugin - NextGEN Gallery » Why hacking $_SERVER['REQUEST_URI']?

  • Hi!

    A lot of Polylang users report a conflict with Nextgen Gallery. When trying to access their gallery, they are redirected to the album page.

    If I try to access /albums/nggallery/my_album/my_gallery
    I am redirected to /albums

    Spending some hours to debug this, I concluded that Polylang is making a redirection based on a wrong information.

    Polylang has a canonical redirection mechanism. But It receives //albums in $_SERVER['REQUEST_URI'] (wrong as I am expecting /albums/nggallery/my_album/my_gallery and worse, malformed due to the two slashes).
    Thus passing this value to the WordPress core function redirect_canonical, it logically returns /albums, different from the requested url known by Polylang, which thus fires the redirection to the wrong url.

    https://wordpress.org/plugins/nextgen-gallery/

Viewing 15 replies - 1 through 15 (of 25 total)
  • Benjamin

    (@benjaminowens)

    Hi Chouby,

    We copy the REQUEST_URI into ORIG_REQUEST_URI to prevent WordPress from treating our “/nggallery/page/2” (for example) as a 404 and redirecting them but it is restored on template_redirect:1

    I’ve reproduced the problem on my machine and you could fix this by checking ORIG_REQUEST_URI in addition to REQUEST_URI, or change the check_canonical_url() action from wp to template_redirect.

    If you’d like to detect for NextGen’s presence you can check if ‘NGG_PLUGIN’ has been defined.

    I hope that helps!

    Hi Benjamin!

    What if you ensure that there is no double slashes in your variable?
    Do you know if ‘NGG_PLUGIN’ is specific to NextGen or common with Nextcellent?

    Benjamin

    (@benjaminowens)

    It’s possible, but I wasn’t responsible for that particular bit of code and don’t know why we chose that particular path. I’ll give it a try though.

    I hadn’t considered Nextcellent; it appears they don’t define NGG_PLUGIN. They do define NGGFOLDER and NGG_DBVERSION like we do, so you could use those with NGG_PLUGIN to detect NextGen or Nextcellent.

    Hi Benjamin!

    Could you look at the double slashes issue with the developper responsible for this part of the code? Is it intentional or a mistake?

    Benjamin

    (@benjaminowens)

    We’re doing what we are intentionally, though the appearance of the double slashes isn’t intentional. Forcing the result to not include a pair of slashes doesn’t seem to have any result, but my original suggestions still apply (inspecting ORIG_REQUEST_URI or using the wp action instead of template_redirect).

    I understood that the modification of REQUEST_URI is intentional. I should not need to modify anything if you fix the double slashes issue.

    Benjamin

    (@benjaminowens)

    In testing the problem I don’t think that’s the case: if I ensure that method comes back with only “/albums” the redirect is still taking place.

    We have made a change so that only “/albums” will be returned which will be a part of the next release.

    We have made a change so that only “/albums” will be returned which will be a part of the next release.

    Thanks 🙂

    if I ensure that method comes back with only “/albums” the redirect is still taking place.

    That’s strange. This worked in my own tests. Is there a place where to download the development version of Nextgen Gallery?

    Plugin Author photocrati

    (@photocrati)

    @chouby – We have a new beta version available here: http://nextgen-gallery.com/nextgen-gallery-latest-beta/

    – Cais.

    Hi!

    Thanks. I tested the beta version 2.0.92 and still $_SERVER['REQUEST_URI'] starts with two slashes.

    Here is a simple plugin to test the issue:

    add_action('wp', 'test_redirection');
    function test_redirection() {
    	$requested_url  = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    	$redirect_url = redirect_canonical($requested_url, false);
    	if ($redirect_url && $redirect_url != $requested_url) {
    			error_log('request: ' . $requested_url);
    			error_log('redirect: ' . $redirect_url);
    			wp_redirect($redirect_url, 301);
    	}
    }

    Plugin Author photocrati

    (@photocrati)

    @chouby – We released a new stable version this morning … please update to that version and let us know how your testing goes.

    Thanks!

    – Cais.

    I just updated to v2.1.0. It does not solve the issue either. I still have //albums/ instead of expected /albums/ in $_SERVER['REQUEST_URI']

    Did you managed to solve problem?

    Plugin Author photocrati

    (@photocrati)

    @pbobek – Please start your own topic so we can try to help you with your specific issue on your specific site.

    See http://codex.wordpress.org/Forum_Welcome#Where_To_Post

    Thanks!

    – Cais.

    Benjamin

    (@benjaminowens)

    I’ve tried your snippet with NextGen 2.1.0 and I’m still only seeing a single /albums/ which does not work and requires changing the check_canonical_url() action from ‘wp’ to ‘template_redirect’ or checking ORIG_REQUEST_URI in addition to REQUEST_URI.

Viewing 15 replies - 1 through 15 (of 25 total)
  • The topic ‘Why hacking $_SERVER['REQUEST_URI']?’ is closed to new replies.