简体   繁体   中英

Drupal get path from redirect url

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

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;
}
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM