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.

Thanks for the Drupal tip
Many thanks for the quick Drupal fix. It was driving me mad!
Thanks!
I'm developing a site for a host that also has the /admin path remapped. Your solution works perfectly. Thanks!
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!
Good one !!
Nice fix !! Was really useful ...
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...
Module conflicts? Yes.
Does not work with Global redirect module, but otherwisenice fix.
Thank you ! This fix is
Thank you ! This fix is really nice !
Post new comment