1

I got a view with contextual filters set up as the following:

  • Global: Null (Fixed value "user")
  • Content: Author uid (User ID from URL)
  • Global: Null (Fixed value "taxonomy")
  • Global: Null (Fixed value "term")
  • Content: Has taxonomy term ID (Taxonomy term ID from URL)

When I go to mysite.com/user/*/taxonomy/term/* I'm being redirected to mysite.com/taxonomy/term/*.

How can I prevent this?

I also got Pathauto to change the URLs to [user:name] for user/* and tags/[term:name]for taxonomy/term/*.

Edit: If I disable the URL alias for the taxonomy terms it still redirects to mysite.com/taxonomy/term/*.

9
  • The redirect cannot be because of the contextual filters. The redirect has been done by some other piece of custom code I guess. Feb 16, 2013 at 11:07
  • It must be either Drupal core or Pathauto I guess, but I still don't know how to fix it. Feb 16, 2013 at 11:18
  • Why cant you change the path to mysite.com/user-profile/*/taxonomy/term/*? By default the /user path has lots to do with. Create a custom path of yours and give a try.
    – Gladiator
    Feb 16, 2013 at 11:51
  • I want the user paths to be mysite.com/[user:name], which means I could change the path in the view to mysite.com/[user:name]/taxonomy/term/* or even mysite.com/[user:name]/tags/[term:name] but then I'd have to get the Author and Taxonomy Term Name instead of the ID, and I don't know how to do that. Feb 16, 2013 at 12:00
  • 1
    Have you determined what is causing the redirect in the first place? That is really your first step. Any solution is a wild guess until you figure out why this is happening.
    – mpdonadio
    Mar 18, 2013 at 16:06

3 Answers 3

5
+25

The source of the redirect could be essentially any module you have, and several modules allow for configuration that will cause redirects as well. You will need find the source of the redirect on for your particular situation.

Suggestions:

  1. Deactivate modules in a 50 / 50 manner. This allows you to quickly narrow down which module is providing the redirect, and hopefully that will help you to work it out. Using drush to disable/enable modules will make this much faster.

  2. Install Devel. It has a settings called "Display redirection page", and implements devel_drupal_goto_alter halting the redirection.

    The primary purpose of this is to gather up debug information that would otherwise go lost due to the redirect. In this particular case, I suggest you add a dpm(debug_backtrace()); into the hook so you can trace the call to the source of the redirect.

  3. Everything else failing, fire up a full debugger, and trace the call, ideally with help from the information provided by the debug_backtrace() above.

1
  • I managed to solve the problem by making the view a little bit different than above. I will accept this answer though since it's probably the way to go. Mar 26, 2013 at 16:09
2

Implement hook_drupal_goto_alter() in a module and

a) put a breakpoint on code in this function and view the call-stack to determine which function is setting the redirect in the first place.

b) change the path.

path is passed by reference so this can be changed directly. Assuming you create a module name ungoto:

ungoto_drupal_goto_alter(&$path, &$options, &$http_response_code) {
   // regular expression can be tightened
   if (preg_match('#^taxonomy/term/', $path)) {
     // Guessing that you are trying to 'display profiles' not display current 
     // users details, so global $user is not useful. 
     // Contextual filters says is is on the path. 
     // OP to do work to extract only the information needed.
     $user_details = $_GET[q];

     // Reset the path
     $path = $user_details . $path;   
   }
}
-1

You could use hook_exit($destination) to change the redirect.

  • Create a new module. I use the Netbeans drupal-7 plugin to create .install, .info and .module files.
  • Fill out the .info template.
  • Implement hook_exit($destination). Call another drupal_goto(). Be careful that it can't create a redirect loop.

Hook Exit passes the destination address, and if you put a debugger on it you may be able to trace the call-stack to find another drupal_goto() that is causing the redirect.

11
  • The OP is interested to know how to stop the redirect, not how to redirect the user again. It is not said that redirecting the user to the first URL doesn't cause a loop.
    – apaderno
    Mar 18, 2013 at 22:35
  • This is changing the redirect, not redirecting again. You may only create redirect loop if you redirect to a page that redirects again. At least check to see that you are not redirecting to the current location. You cannot redirect twice in one http request.
    – Interlated
    Mar 19, 2013 at 11:46
  • The OP notices a redirect from mysite.com/user/*/taxonomy/term/* to mysite.com/taxonomy/term/* that he doesn't want. This means the solution should be avoiding that redirect is done. Your solution is redirecting from mysite.com/taxonomy/term/* to mysite.com/user/*/taxonomy/term/*. Isn't that a loop? The code that is causing the redirect (possibly PHP code) would probably cause the redirect again.
    – apaderno
    Mar 19, 2013 at 12:29
  • Probably not isn't it? He is targeting mysite.com/user/*/taxonomy/term/* and drupal has been programmed to redirect to mysite.com/taxonomy/term/*. Another goto() at the end would just undo the previous goto(). Of course it would be better to find the original goto(), but that could be impossible due to modules.
    – Interlated
    Mar 19, 2013 at 13:12
  • Looking at the code for drupal_goto() there is an even better option. hook_drupal_goto_alter() is called. This could have 2 uses a) breakpoint to find out where the drupal_goto() is coming from and b) change the path - passed as reference api.drupal.org/api/drupal/modules!system!system.api.php/…
    – Interlated
    Mar 19, 2013 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.