0

I would like to know if there is any way in Drupal that given a url that is a redirect of another url get the original one.

Ie, I have a url and alias as: /prices/old-vehicles -> node/112

and I have and url redirect as ->

/old-vehicles-pricing -> /prices/old-vehicles

I would like to write a function to obtain "/prices/old-vehicles" from "/old-vehicles-pricing"

Thanks.

Update

I will try to elaborate a little bit on the scenario. Say that a user lands to old-vehicles-pricing, then he is redirected to the /prices/old-vehicle which is the alias of node/112. All correct.

Now say that the user lands on /de/old-vehicles-pricing (german version). That url redirect does not exist. Although I can create a redirect for that specific page, I am trying to get a general solution. So what I am trying to do is to intercept the invalid url, strip out the language prefix, and get the original url for that url. Ie, Step 1. I intercept request to /de/old-vehicles-pricing Step 2. I take "old-vehicles-pricing" Step 3. I obtain original alias or canonical url ( either /prices/old-vehicles or node/112) Step 4. I obtain the translated version of the canonical url Step 5. I redirect the user to the new translated url

I only need to resolve Step 3. I have implemented all the other steps.

Also, I know that the user should never land in "/de/old-vehicles-pricing" for starting. But that is something out of my control and that is the reason I am trying to implement this solution.

Thanks

apaderno
  • 28,547
  • 16
  • 75
  • 90
vicpada
  • 65
  • 11
  • I don't understand. When you go to /old-vehicles-pricing, you want to directly redirect to /prices/old-vehicles and never ever arrive on the original page? Why does this page exist so? – Djouuuuh Apr 16 '14 at 12:42
  • Please see my updated above – vicpada Apr 16 '14 at 13:32

1 Answers1

0

Even if I don't understand why you created a page only for redirect people on your other page, here is a solution to write in a custom module:

<?php
/**
* Implements hook_menu
*/
function mymodule_menu() {
  $menu['old-vehicles-pricing'] = array(
    'title' => 'Old vehicles pricing',
    'page callback' => 'drupal_goto',
    'page arguments' => 'prices/old-vehicles',
    'access callback' => 'whetever-you-want',
  );
  return $menu;
}
?>
Djouuuuh
  • 1,147
  • 8
  • 16
  • Hi Justine, thanks for your response. I think I didnt provide enough context as to what I am trying to do. Please see my updated above – vicpada Apr 16 '14 at 13:32
  • Is that only a multilingual url issue? Because I think that i18n module manages url redirections when url doesn't exist in a certain language. – Djouuuuh Apr 16 '14 at 13:37
  • yes it is a multilingual issue. But the problem is not that I am accesing a page that does not exist in a language. The page does indeed exist in all the languages. What I am trying to achieve is that when someone lands in a wrong page like "/de/old-pricing" and there is a url redirect for "old-pricing" redirect the user to the appropiate page. My issue really is how to get the url alias or canonical url from a url redirect – vicpada Apr 16 '14 at 14:33
  • So, you want to remember the page where you are from before being redirected to the other one? I suggest you to use [variable_set](https://api.drupal.org/api/drupal/includes!bootstrap.inc/function/variable_set/7) to save your [current_path()](https://api.drupal.org/api/drupal/includes!path.inc/function/current_path/7) before redirecting. It will save the "node/17854" path in a variable. – Djouuuuh Apr 16 '14 at 14:46
  • No, the user lands on /de/old-pricing which at the moments returns 404. What I want to do is to get the canonical url of the default language (ie for /old-pricing -> /prices/old-vehicles -> node/112) and then the translated version. Ie I can get the canonical url from /prices/old-vehicles using drupal_lookup_path(). I can get the translated urls from the canonical using translation_path_get_translations(). What I don´t know is how to get the alias url (/prices/old-vehicles) from the redirect url (/old-vehicles-pricing) – vicpada Apr 16 '14 at 16:43