Title: Why hacking $_SERVER[&#039;REQUEST_URI&#039;]?
Last modified: August 24, 2016

---

# Why hacking $_SERVER['REQUEST_URI']?

 *  [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/why-hacking-_serverrequest_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/](https://wordpress.org/plugins/nextgen-gallery/)

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

1 [2](https://wordpress.org/support/topic/why-hacking-_serverrequest_uri/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/why-hacking-_serverrequest_uri/page/2/?output_format=md)

 *  [Benjamin](https://wordpress.org/support/users/benjaminowens/)
 * (@benjaminowens)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/why-hacking-_serverrequest_uri/#post-6053792)
 * 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!
 *  Thread Starter [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/why-hacking-_serverrequest_uri/#post-6053796)
 * 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](https://wordpress.org/support/users/benjaminowens/)
 * (@benjaminowens)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/why-hacking-_serverrequest_uri/#post-6053797)
 * 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.
 *  Thread Starter [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [11 years ago](https://wordpress.org/support/topic/why-hacking-_serverrequest_uri/#post-6053989)
 * 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](https://wordpress.org/support/users/benjaminowens/)
 * (@benjaminowens)
 * [11 years ago](https://wordpress.org/support/topic/why-hacking-_serverrequest_uri/#post-6053999)
 * 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).
 *  Thread Starter [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [11 years ago](https://wordpress.org/support/topic/why-hacking-_serverrequest_uri/#post-6054001)
 * 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](https://wordpress.org/support/users/benjaminowens/)
 * (@benjaminowens)
 * [11 years ago](https://wordpress.org/support/topic/why-hacking-_serverrequest_uri/#post-6054015)
 * 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.
 *  Thread Starter [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [11 years ago](https://wordpress.org/support/topic/why-hacking-_serverrequest_uri/#post-6054019)
 * > 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 Contributor [photocrati](https://wordpress.org/support/users/photocrati/)
 * (@photocrati)
 * [11 years ago](https://wordpress.org/support/topic/why-hacking-_serverrequest_uri/#post-6054020)
 * [@chouby](https://wordpress.org/support/users/chouby/) – We have a new beta version
   available here: [http://nextgen-gallery.com/nextgen-gallery-latest-beta/](http://nextgen-gallery.com/nextgen-gallery-latest-beta/)
 * – Cais.
 *  Thread Starter [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [11 years ago](https://wordpress.org/support/topic/why-hacking-_serverrequest_uri/#post-6054023)
 * 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 Contributor [photocrati](https://wordpress.org/support/users/photocrati/)
 * (@photocrati)
 * [11 years ago](https://wordpress.org/support/topic/why-hacking-_serverrequest_uri/#post-6054026)
 * [@chouby](https://wordpress.org/support/users/chouby/) – We released a new stable
   version this morning … please update to that version and let us know how your
   testing goes.
 * Thanks!
 * – Cais.
 *  Thread Starter [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [11 years ago](https://wordpress.org/support/topic/why-hacking-_serverrequest_uri/#post-6054027)
 * 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']`
 *  [pbobek](https://wordpress.org/support/users/pbobek/)
 * (@pbobek)
 * [11 years ago](https://wordpress.org/support/topic/why-hacking-_serverrequest_uri/#post-6054035)
 * Did you managed to solve problem?
 *  Plugin Contributor [photocrati](https://wordpress.org/support/users/photocrati/)
 * (@photocrati)
 * [10 years, 12 months ago](https://wordpress.org/support/topic/why-hacking-_serverrequest_uri/#post-6054036)
 * [@pbobek](https://wordpress.org/support/users/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](http://codex.wordpress.org/Forum_Welcome#Where_To_Post)
 * Thanks!
 * – Cais.
 *  [Benjamin](https://wordpress.org/support/users/benjaminowens/)
 * (@benjaminowens)
 * [10 years, 12 months ago](https://wordpress.org/support/topic/why-hacking-_serverrequest_uri/#post-6054037)
 * 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)

1 [2](https://wordpress.org/support/topic/why-hacking-_serverrequest_uri/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/why-hacking-_serverrequest_uri/page/2/?output_format=md)

The topic ‘Why hacking $_SERVER['REQUEST_URI']?’ is closed to new replies.

 * ![](https://ps.w.org/nextgen-gallery/assets/icon-256x256.png?rev=2083961)
 * [Photo Gallery, Sliders, Proofing and Themes - NextGEN Gallery](https://wordpress.org/plugins/nextgen-gallery/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/nextgen-gallery/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/nextgen-gallery/)
 * [Active Topics](https://wordpress.org/support/plugin/nextgen-gallery/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/nextgen-gallery/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/nextgen-gallery/reviews/)

 * 25 replies
 * 8 participants
 * Last reply from: [photocrati](https://wordpress.org/support/users/photocrati/)
 * Last activity: [10 years, 6 months ago](https://wordpress.org/support/topic/why-hacking-_serverrequest_uri/page/2/#post-6054106)
 * Status: not a support question