How can I trace the source of a redirect error listed in Administration -> Reports? Under Reports -&gt; Recent log messages, I have a large number of errors such as the following:


Type: access denied
Date: November 7, 2013
User: Anonymous
Location: https://mysite.com/ja/user/en/user/register
Referrer: http://mysite.com/ja/user/en/user/register
Message: user/en/user/register
Severity: warning


I have a multilingual site (English en and Japanese ja), so I assume that somewhere there is a bad link or a module is outputting a bad link to the registration page.  How can I find out where?  The only clue I have is this entry in the recent error log.

When I visit the link (http://mysite.com/ja/user/en/user/register), I get a "The page isn't redirecting properly.  Firefox has detected that the server is redirecting the request for this address in a way that will never complete."
If you know the name of the failing redirect URI (such as user/register), the best is to scan through your database and look for redirect entries, e.g. using drush:

drush sql-dump --ordered-dump | grep "user/register"




Alternatively add dd() (from Devel) into drupal_goto() and log the backtrace of each call into the file, e.g.

dd(debug_backtrace(FALSE, 5));


and check drupal_debug.txt in your tmp folder.



Another trick include using DTrace and hook into static probes (if your PHP supports that: php -i | grep dtrace), for example (after running the script):

sudo dtrace -qn 'php*:::function-entry { printf("%Y: PHP function-entry:\t%s%s%s() in %s:%d\n", walltimestamp, copyinstr(arg3), copyinstr(arg4), copyinstr(arg0), basename(copyinstr(arg1)), (int)arg2); }'


then you may grep it and look for specific functions such as drupal_goto, so you may append to above:

| grep -B5 drupal_goto &gt; trace.txt


so this will log into file all calls to drupal_goto with 5 function calls before.

See also: How to generate the function stack trace of the last request made?