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 (2)

Add new comment

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