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 tohttp://www.abcd.com/username
& not tohttp://www.abcd.com/user/1
2)drupal_goto("node/1");
should take user tohttp://www.abcd.com/nodetitle
& not tohttp://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
The global redirect module
The global redirect module will handle this for you. It automatically redirects to aliases.
It Worked
Hi,
Thanks. that helped :)
If you care about performance
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.
What's new and changing in PHP 8
Really Late Reply. (Off Topic)
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.
.
अंत में हम मिले!
What's new and changing in PHP 8