On one of our D8 sites, after upgrading to 8.3.0, we had a "too many redirects" loop going on on the dev server. For quite some time, we've had the site path repeated with "?q=".

Tracked this down to a trick with the rewrite blocks we had in our Nginx virtual host config. Our config was built to support both Drupal 6 and Drupal 7 with different rewrite blocks. The essence:

        location / {
                # This is cool because no php is touched for static content
                try_files $uri @rewrite7 @rewrite6;
        location @rewrite7 {
                # You have 2 options here
                # For D7 and above:
                # Clean URLs are handled in drupal_environment_initialize().
                rewrite ^ /index.php;
        location @rewrite6 {
                # For Drupal 6 and bwlow:
                # Some modules enforce no slash (/) at the end of the URL
                # Else this rewrite block wouldn't be needed (GlobalRedirect)
                rewrite ^/(.*)$ /index.php?q=$1;

... The problem was, the "try_files" section was skipping over the @rewrite7 block and going straight to @rewrite6. And in this case it was leading to a redirect loop that appended another q= parameter until the server killed the request.

It turns out that try_files only checks for an existence of a file pattern, and redirects to the last item in its list only if a file does not exist in the earlier patterns. So providing two named locations does not work -- it will follow the second one because the first is not evaluated, it is simply checked literally.

Simple fix -- remove the @rewrite6 section. Drupal 6 doesn't work on PHP7 anyway.

Share this article with your friends!

Comments (4)

This seems to be some sort of Kalabox issue I'm running into that's causing the ?q= to be output on every page, it just wasn't causing an infinite redirect loop until the new version of redirect was installed today. I suppose I'll roll back redirect until the issue in Kalabox is figured out. Thanks for your assistance.

16 May, 2018

Add new comment

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.