Tony's ramblings on Open Source Software, Life and Photography

Moving The Admin And User Pages In Drupal

I have a web host for one of my sites that overrides all URL's that begin with /admin or /user. Why both, I don't know, but they redirect both of those to their own administration console login.

That kind of throws a monkey wrench in setting up Drupal, which when using Clean URL's requires both of those and will conflict with the host redirect.

So, I found a little known trick of URL rewriting in Drupal 6 to cause both of those URL's to change for the entire site. Add the following lines to the bottom of your settings.php file:

function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
  // Change all 'admin' to 'adm'.
  if (preg_match('|^admin(/.*)|', $path, $matches)) {
    $path = 'adm'. $matches[1];
  }
  // Change all 'user' to 'usr'.
  if (preg_match('|^user(/.*)|', $path, $matches)) {
    $path = 'usr'. $matches[1];
  }
  if ($path == 'admin') {
    $path = 'adm';
  }
  if ($path == 'user') {
      $path = 'usr';
   }
} 

function custom_url_rewrite_inbound(&$result, $path, $path_language) {
  if ($path == 'adm') {
    $result = 'admin';
  }
  if ($path == 'usr') {
    $result = 'user';
  }
  if (preg_match('|^adm(/.*)|', $path, $matches)) {
    $result = 'admin'. $matches[1];
  }
  if (preg_match('|^usr(/.*)|', $path, $matches)) {
    $result = 'user'. $matches[1];
  }
}

After that quick fix, your Drupal site will now use /adm and /usr for the appropriate subdirectories.


Categories:
Catherine's picture

Thanks for the Drupal tip

Many thanks for the quick Drupal fix. It was driving me mad!

Tyler Ham's picture

Thanks!

I'm developing a site for a host that also has the /admin path remapped. Your solution works perfectly. Thanks!

Fred's picture

Thanks

My host uses the Parallels Control Panel (was Ensim) which uses admin & user. Instead of the above, after installing Drupal 6 I went to /admin/build/modules (urls below admin are passed to Drupal) and enabled the Path module, then went to /admin/build/path and set url aliases there.

I haven't had any issues doing it that way yet, but then it's only been installed for about 15 mins!

Manu's picture

Good one !!

Nice fix !! Was really useful ...

Charles's picture

Doesn't work...

Copied and pasted to the end of my settings.php file. Did update.php. It tries to redirect to /adm but nothing loads. Instead /admin still works.. =?

Module conflicts? I have path_auto installed. I also have Global Redirect but all that does it make a 301 redirect...

Anonymous n00b's picture

Module conflicts? Yes.

Does not work with Global redirect module, but otherwisenice fix.

Pribooster's picture

Thank you ! This fix is

Thank you ! This fix is really nice !

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <br> <p>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for preventing automated spam submissions. It is case sensitive.
Image CAPTCHA
Enter the characters shown in the image.