2

I have a problem with integrating the Pathauto and Profiles modules. Basically, I would like to have the username as URL, e.g. example.com/username. This should link to the profile page (not the account page). I know how to do it for account ([user:name]) however this method does not work for the profile patterns. There is only certain number of patterns available for profile paths and no username I am afraid. I tried node:author:name, but this doesnt work as well?

Can anyone help with this, or suggest any other solution?

2
  • Whats the url pattern of the actual profile?
    – Dipen
    Jan 28, 2012 at 15:15
  • Have you tried adding the pattern to the content type of profile i path auto?
    – frazras
    Jul 4, 2012 at 5:45

1 Answer 1

2

you can automatically path save the user name when user access the user/uid page add a submit handler in form alter and

$form['#submit'][1] = 'redirect_to_profile_username_page'; 

// here get the user name field

function redirect_to_profile_detail(&$form, &$form_state){
$uid = $form_state['build_info']['args'][0]->uid;
$user = user_load($uid);
$clean = $user->name;
      $Alias_1 = get_alias('source','user/'.$uid,1);
        $pathAlias = !empty($Alias_1) ? $Alias_1['alias'] : FALSE;
        if($pathAlias === FALSE){
                path_save($args = array("source" => 'user'.'/'.$uid,"alias" => $clean));
                $pathAlias = drupal_lookup_path('alias',$clean);
        }
       $form_state['redirect'] = $clean;
     }

this will redirect the user/uid page to that particular username as url page

here we are creating a aliase for user/uid so when you access sitename/username that user profile page will be loaded.

1
  • you can also give the aliase in pathauto module pattern will help you out Feb 12, 2015 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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