I've just started getting the "too many redirects" browser error on our dev site, and since the only way to escape it is to delete cookies, I can't log in to try and fix it.
I have searched a number of previous cases but haven't found a match for probable cause yet.
- We're not (yet) using https or any settings/modules relating to it.
- We are using pathauto
- no recent manual changes to .htaccess
- we are using login-destination, but with a destination setting of - this was installed after we started getting the error (I still had a login at that point)
- we haven't (yet) overridden the login form.
Logging in or trying to go to the home page with cookies always results in an attempt to load /?q=users/webmaster

Version 7.50

I have managed to disable pathauto via drush

Is there any way to debug the redirects which are happening?

Richard

Comments

Stefan Lehmann’s picture

Is there any way to debug the redirects which are happening?

Did you try to write a rewrite log, like described here: http://stackoverflow.com/questions/9632852/how-to-debug-apache-mod-rewrite

I like cookies!

permaculturegeek’s picture

Ok, done that. Amid all the weird numbers the page seems to be flipping between / and /index.php

118.149.129.107 - - [29/Sep/2016:06:56:37 +1300] [dev.permaculture.org.nz/sid#7f9ab2164050][rid#7f9ab24d1048/initial] (1) pass through /
118.149.129.107 - - [29/Sep/2016:06:56:37 +1300] [dev.permaculture.org.nz/sid#7f9ab2164050][rid#7f9ab24cf038/subreq] (2) init rewrite engine with requested uri /index.php
118.149.129.107 - - [29/Sep/2016:06:56:37 +1300] [dev.permaculture.org.nz/sid#7f9ab2164050][rid#7f9ab24cf038/subreq] (1) pass through /index.php
118.149.129.107 - - [29/Sep/2016:06:56:39 +1300] [dev.permaculture.org.nz/sid#7f9ab2164050][rid#7f9ab24d1048/initial] (2) init rewrite engine with requested uri /
118.149.129.107 - - [29/Sep/2016:06:56:39 +1300] [dev.permaculture.org.nz/sid#7f9ab2164050][rid#7f9ab24d1048/initial] (1) pass through /
118.149.129.107 - - [29/Sep/2016:06:56:39 +1300] [dev.permaculture.org.nz/sid#7f9ab2164050][rid#7f9ab24cf038/subreq] (2) init rewrite engine with requested uri /index.php

Here's .htaccess with the comments stripped:

#
# Apache/PHP/Drupal settings:
#
<FilesMatch "\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)(~|\.sw[op]|\.bak|\.orig|\.save)?$|^(\..*|Entries.*|Repository|Root|Tag|Template|composer\.(json|lock))$|^#.*#$|\.php(~|\.sw[op]|\.bak|\.orig\.save)$">
  Order allow,deny
</FilesMatch>

Options -Indexes
Options +FollowSymLinks
ErrorDocument 404 /index.php
DirectoryIndex index.php index.html index.htm

<IfModule mod_php5.c>
  php_flag magic_quotes_gpc                 off
  php_flag magic_quotes_sybase              off
  php_flag register_globals                 off
  php_flag session.auto_start               off
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_flag mbstring.encoding_translation    off
</IfModule>

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault A1209600

  <FilesMatch \.php$>
    ExpiresActive Off
  </FilesMatch>
</IfModule>

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteRule ^ - [E=protossl]
  RewriteCond %{HTTPS} on
  RewriteRule ^ - [E=protossl:s]
  RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  RewriteRule "(^|/)\." - [F]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^ index.php [L]
  <IfModule mod_headers.c>
    # Serve gzip compressed CSS files if they exist and the client accepts gzip.
    RewriteCond %{HTTP:Accept-encoding} gzip
    RewriteCond %{REQUEST_FILENAME}\.gz -s
    RewriteRule ^(.*)\.css $1\.css\.gz [QSA]

    # Serve gzip compressed JS files if they exist and the client accepts gzip.
    RewriteCond %{HTTP:Accept-encoding} gzip
    RewriteCond %{REQUEST_FILENAME}\.gz -s
    RewriteRule ^(.*)\.js $1\.js\.gz [QSA]

    # Serve correct content types, and prevent mod_deflate double gzip.
    RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
    RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]

    <FilesMatch "(\.js\.gz|\.css\.gz)$">
      # Serve correct encoding type.
      Header set Content-Encoding gzip
      # Force proxies to cache gzipped & non-gzipped css/js files separately.
      Header append Vary Accept-Encoding
    </FilesMatch>
  </IfModule>
</IfModule>

<IfModule mod_headers.c>
  Header always set X-Content-Type-Options nosniff
</IfModule>
Stefan Lehmann’s picture

I think I know what's causing this. Have a look in your settings.php, there is probably a setting like:

$conf['https'] = TRUE; 

because you copied the settings file over from the live site. But your dev-subdomain doesn't support HTTPS so it pingpongs between HTTP and HTTPS requests.

I hope that was it. .. and greetings from Wellington! :-)

I like cookies!

permaculturegeek’s picture

Nope - only references to https in settings.php are in comments. And this was a from-scratch Drupal install.
But the port 443 virtualhost and the certs are all set up for this dev site, (and throwing in an https:// lets the site load ok - haven't tried logging in yet) so maybe the best approach is to complete implementing secure hosting.

permaculturegeek’s picture

...and I'm still getting the error. But the higher level or rewrite log reporting seems to have kicked in at last:

118.149.135.16 - - [02/Oct/2016:00:18:50 +1300] [dev.permaculture.org.nz/sid#7f851d61e050][rid#7f851d992c78/i                                                           nitial] (2) init rewrite engine with requested uri /
118.149.135.16 - - [02/Oct/2016:00:18:50 +1300] [dev.permaculture.org.nz/sid#7f851d61e050][rid#7f851d992c78/i                                                           nitial] (1) pass through /
118.149.135.16 - - [02/Oct/2016:00:18:50 +1300] [dev.permaculture.org.nz/sid#7f851d61e050][rid#7f851d992c78/i                                                           nitial] (3) [perdir /var/www/dev.permaculture.org.nz/public_html/] strip per-dir prefix: /var/www/dev.permacu                                                           lture.org.nz/public_html/ ->
118.149.135.16 - - [02/Oct/2016:00:18:50 +1300] [dev.permaculture.org.nz/sid#7f851d61e050][rid#7f851d992c78/i                                                           nitial] (3) [perdir /var/www/dev.permaculture.org.nz/public_html/] applying pattern '^(.*)$' to uri ''
118.149.135.16 - - [02/Oct/2016:00:18:50 +1300] [dev.permaculture.org.nz/sid#7f851d61e050][rid#7f851d992c78/initial] (4) [perdir /var/www/dev.permaculture.org.nz/public_html/] RewriteCond: input='off' pattern='off' =>                                                            matched
118.149.135.16 - - [02/Oct/2016:00:18:50 +1300] [dev.permaculture.org.nz/sid#7f851d61e050][rid#7f851d992c78/initial] (2) [perdir /var/www/dev.permaculture.org.nz/public_html/] rewrite '' -> 'https://dev.permaculture.org.nz/'
118.149.135.16 - - [02/Oct/2016:00:18:50 +1300] [dev.permaculture.org.nz/sid#7f851d61e050][rid#7f851d992c78/initial] (2) [perdir /var/www/dev.permaculture.org.nz/public_html/] explicitly forcing redirect with https://dev.permaculture.org.nz/
118.149.135.16 - - [02/Oct/2016:00:18:50 +1300] [dev.permaculture.org.nz/sid#7f851d61e050][rid#7f851d992c78/initial] (1) [perdir /var/www/dev.permaculture.org.nz/public_html/] escaping https://dev.permaculture.org.nz/  for redirect
118.149.135.16 - - [02/Oct/2016:00:18:50 +1300] [dev.permaculture.org.nz/sid#7f851d61e050][rid#7f851d992c78/initial] (1) [perdir /var/www/dev.permaculture.org.nz/public_html/] redirect to https://dev.permaculture.org.nz/ [REDIRECT/301]

This is after adding AllowOverrides ALL to the Virtual hosting buckets and putting the following redirect in .htaccess:
(immediately after rewriteEngine on)

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^dev.permaculture\.org\.nz*
RewriteRule ^(.*)$ https://dev.permaculture.org.nz/$1 [L,R=301]

Also, RewriteBase / is now uncommented.

permaculturegeek’s picture

I have replaced .htaccess with a clean one from the dristro (and moved the forced redirect to https into the virtualhost bucket for port 80) and I can access the site so long as I'm not logged in. But logging in still gives the too many redirects error. The rewrite log is empty, but the ssl_requests log shows a succession of GET requests to /?q=users/webmaster - so the problem seems to lie within drupal system/mosules rather than settings or .htaccess.

Here's the contrib modules list:
civicrm
ctools
date
devel
disable_html5_validation
elements
html5_tools
image_field_caption
libraries
login_destination
pathauto
simple_gmap
token
views
wysiwyg

...of which pathauto has been disabled since the problem developed, and login_destination is configured as
civicrm was installed just prior to the problem developing.
devel is installed but not configured to do anything.

Stefan Lehmann’s picture

Can't you just disable login_destination for a test? Seems like a good candidate to cause such behavior?

I like cookies!

permaculturegeek’s picture

Installing login_destination (which was always intended) was an early attempt to FIX the problem (it was already happening but I still had an admin session going in another browser).

permaculturegeek’s picture

I didn't explicitly empty caches (via drush) after resetting the .htaccess file, but it came right the next day.

Stefan Lehmann’s picture

So all is good now? In D7 you can also manually clear the cache by truncating all tables beginning with "cache_".

I like cookies!

marcos12’s picture

same problem on my website any help

permaculturegeek’s picture

replace your .htaccess file with a known-good one (e.g. from the drupal distro if you don't have a working copy of your site.
Then, if you have drush installed, issue the command drush cc
otherwise, just wait for caches to expire.
I think that's what fixed it for me.

deanflory’s picture

I was having numerous permissions problems when doing a clean install with Drupal 8. I thought I got smart and went ahead and set the database, public file, and private file settings in the settings.php file before running the initial drupal install. This in turn caused the loading of the site in a browser to fail with a WSOD from too many redirects. Going back to a clean, uninstalled version without a pre-set-up settings.php file did the trick to get the initial install working again.

RAWDESK’s picture

Hi,
We are getting the same error on a site where pathauto and entity translation are enabled.
Use case :
- Content manager creates a job event (node/1) in language X, pathauto sets URL alias to title-x (based on content title)
- Content manager translates job event (node/1) to language Y, pathauto sets URL alias to title-y (based on translated content title)
After some time :
- Content manager changes title to "New Title X" -> URL alias is changed to new-title-x for language X
- Content manager changes translated title to "New Title Y" -> URL alias is changed to new-title-y for language Y
- In both cases, at admin/config/search/redirect, an additional redirect is automatically added to the list of target node/1 for both language.
- From then on the "too many redirects error" is occurring when viewing node/1, but only for language Y
- After removal of the redirects for language Y, the error disappears.

So what i would like to achieve is replacement of redirects, instead of additions since the old path alias (title-Y and title-X) are no longer leading to actual content.
Or any other solution that might break this "annoying" infinite redirect looping.