I'd like to create a redirect so when the user hits mydrupal.com/my-account its redirected to mydrupal.com/users/3

I'm using Pathauto and I know I can go to admin/config/search/path/add to add the redirect but I can't get it to point to the user id as variable. For instance, in the existing system path option I thought I could add users/[uid] but that didn't work.

Any suggestions?

  • 1
    Why are you not redirecting /my-account to /user ? It will lead to the user profile page, If he/she is logged in. – Pravin Ajaaz Jul 27 '15 at 10:49
  • That's exactly what I wanted! Do you want to add as an answer? – WagnerMatosUK Jul 27 '15 at 12:20
  • Let me add it so that the question will not be open. – Pravin Ajaaz Jul 27 '15 at 13:34

Instead of redirecting the mydrupal.com/my-account to particular user ID as mydrupal.com/users/3

You should redirect them to mydrupal.com/user which will lead them to thier profile page if the user is logged in.

|improve this answer|||||

As an alternative, you could also use the Rules module for this.

Here is the rule you'd need for it (in Rules export format, just use copy/past to import it in your own setup):

{ "rules_redirect_an_old_path_to_a_new_path" : {
    "LABEL" : "Redirect an old path to a new path",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "init" : [] },
    "IF" : [
      { "text_matches" : {
          "text" : [ "site:current-page:url" ],
          "match" : "the_old_path",
          "operation" : "starts"
    "DO" : [
      { "drupal_message" : { "message" : "Sorry, the old path (= /the_old_path) is no longer in use, you will be redirected automatically to its corresponding path (= /the_new_path)" } },
      { "redirect" : { "url" : "the_new_path" } }

A few more tweaks to make it fit your exact scenario:

  • change all occurences of the_old_path to my-account.
  • change all occurences of the_new_path to user.

Whenever such redirect actually happens, the user will also receive an informational message like so:

Sorry, the old path (= /my-account) is no longer in use, you will be redirected automatically to its corresponding path (= /user)

If you don't want such message to appear, then just delete the line containing drupal_message in the exported rule above.

Note: No Pathauto involved using this approach, just Rules.

|improve this answer|||||

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.