Hi,

I have a drupal 7 website already built & i need to give aliases to "User/uid"(user) & "Node/nid"(node) pages.

I used pathauto module & generated bulk aliases for user and node pages, Till here everything works fine.

drupal_goto & URL Patterns:
I have written more than 15 custom modules on site, & have used drupal_goto() at many places for redirecting users back to user & node pages using this format...

1) http://www.abcd.com/user/1 -> [drupal_goto('user/1')]
2) http://www.abcd.com/node/1 -> [drupal_goto('node/1')]

My pathauto URL patterns for user and node pages are as followed...

1) user page -> http://www.abcd.com/username
2) node page -> http://www.abcd.com/nodetitle

Problem:
I want automatic redirection to occur to node & user pages in the following way...

1) drupal_goto("user/1"); should take user to http://www.abcd.com/username & not to http://www.abcd.com/user/1
2) drupal_goto("node/1"); should take user to http://www.abcd.com/nodetitle & not to http://www.abcd.com/node/1

Has anybody done something like this before ?

Please note: I do not want to use hook_url_inbound_alter() & hook_url_outbound_alter() , since they can affect site performance.

Comments

Jaypan’s picture

The global redirect module will handle this for you. It automatically redirects to aliases.

kunalkursija’s picture

Hi,

Thanks. that helped :)

Ayesh’s picture

If you care about performance, you wouldn't be using Global Redirect module.
I like the module but note that it uses hook_init on your landing page to do the redirection.

So in this case, you are not sending user to /username from the page. Instead, you send user to /user/1 first, where global redirect module redirects him to /username.

hook_init is an critical hook to implement, and at this point, your database is initialized, and most of the page request is done already.

drupal_goto() DOES handle url aliases. If you see the function code, it calls url(), which resolves path aliases.
See if you have any other modules implementing drupal_goto_alter, and try calling url('node/1') to see if it returns the aliased path.

----
By the way, I see you are from Mumbai. Did you come to the Drupal Camp Mumbai on feb 7/8? It was in IIT Bombay. I'm not from India but had a great time with you guys.

kunalkursija’s picture

Hi Ayesh,

Man it just popped me today that you had been to drupalcamp mumbai last year (2015). I see you attending DRUPALCONASIA 2016 which begin's tomorrow.

Hope to see you there.

Ayesh’s picture

अंत में हम मिले!