1

I'm migrating an older site into Drupal 7 and have had a lot of success so far. One item where I'm stumped is on links to user profiles. The older system would link to teachers via

site.edu/faculty.php?PID=FirstnameLastname

Might there be a way to effectively copy that URL as the page's alias faculty.php?PID=FirstnameLastname? And yes, is there a way to escape the http encodings (?, =, and &)?

2

There's no real need to escape the URI string.

Here's one way to handle this:

  1. In a custom module, implement hook_menu(), creating an item for the path 'faculty.php'

  2. In your php function callback for the above path, look at the PID value, look up the new path (you do have a database table mapping old content to new content, right? :) ), and do a 301 redirect.

Another approach is to do this lookup on all 404 pages with something like the following code in a hook_init():

function hook_init() {
  if (!menu_get_item($_GET['q'])) {
    $pid = isset($_GET['PID']) ? $_GET['PID'] : FALSE;

    if ($pid) {
      // lookup new path and 301 to it
    }
  }
}
5
  • One gotcha on this, is that hook_init() doesn't run on cached pages. Any suggestions for a work around? – Rick Mar 15 '13 at 21:34
  • @Richard Did you try the hook_menu thing? That is really the best option. – mpdonadio Mar 15 '13 at 23:00
  • if faculty.php is the only legacy page you need to redirect you could create a faculty.php file in your root and write non-drupal php to redirect to the correct page. – uwe Mar 16 '13 at 16:09
  • @MotoTribe, the problem with that is not having access to Drupal's framework, meaning you'd have to write your own database access code (so you can query the db and figure out the destination), essentially duplicating your work. – Yuriy Babenko Mar 18 '13 at 4:21
  • you could include the Drupal bootstrap in that file interworks.com/blogs/jkhalaj/2012/05/01/how-bootstrap-drupal – uwe Mar 18 '13 at 4:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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