Changing "user" and "admin" URLs (host automatically redirects)

bmann@blogger.com - August 8, 2003 - 03:27

I have kind of a strange/unique problem (I think). My host uses Ensim, which automatically forwards www.domain.com/user and www.domain.com/admin to it's back-end control panel interface. Obviously, this interferes with Drupal, since any of the clean URL's that start with either of those two won't work.

Where is this stuff kept (i.e. which module or include file)? Is there a way to change the URLs that Drupal uses?

I thought of using mod_rewrite, but it looks like the hosts re-directs take precedence -- i.e. my .htaccess file with mod_rewrite doesn't get read before the redirect.

Bright ideas appreciated...

maybe try the redirect.module?

erikhopp - August 8, 2003 - 06:23

it is on the download page

Nope

bmann@blogger.com - August 8, 2003 - 15:23

No -- the URLs are re-directed at the Apache level, set globally for all virtual hosts on the system. Those two URLs never even make it through to Drupal.

--
Boris Mann

rewriting links

scott_ - August 8, 2003 - 19:08

Because most (or all) modules use common functions to create links, this could be done by modifying those functions.

The following seems to work on my system (tho i haven't done much testing):
in includes/common.inc, add this to the beginning of function url():

  $fields = explode("/", $url);
  if ($fields[0] == "admin") {
    $fields[0] = "administration";
  }
  $url = implode("/", $fields);

And add this to your .htaccess file, before the existing rule:

  RewriteRule ^administration(.*)$ index.php?q=admin$1 [L,QSA]

I can't garantee this will solve all problems, but its a start.

Frickin' Brilliant!

bmann@blogger.com - August 8, 2003 - 20:46

Nice work! That exactly did the trick for me. I added an else if that did the same thing for "user", renaming it to "usr".

That did indeed solve all the problems. Two thumbs up.

--
Boris Mann

since you seem to be in the same boat as me...

lowcarbkitten - September 4, 2003 - 08:28

does your .htaccess file look like this:

<IfModule mod_rewrite.c>
  RewriteEngine on

  # Rewrite old-style URLS of the form 'node.php?id=x':
  #RewriteCond %{REQUEST_FILENAME} !-f
  #RewriteCond %{REQUEST_FILENAME} !-d
  #RewriteCond %{QUERY_STRING} ^id=([^&]+)$
  #RewriteRule node.php drupal/index.php?q=node/view/%1 [L]

  # Rewrite old-style URLs of the form 'module.php?mod=x':
  #RewriteCond %{REQUEST_FILENAME} !-f
  #RewriteCond %{REQUEST_FILENAME} !-d
  #RewriteCond %{QUERY_STRING} ^mod=([^&]+)$
  #RewriteRule module.php drupal/index.php?q=%1 [L]
 
  # Rewrite URLs of the form 'index.php?q=x':
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^administration(.*)$ index.php?q=admin$1 [L,QSA]
  RewriteRule ^usr(.*)$ drupal/index.php?q=user$1 [L,QSA]
  RewriteRule ^(.*)$ drupal/index.php?q=$1 [L,QSA]
</IfModule>

I'm using drupal/ as my Drupal directory.

Works fine

bmann@blogger.com - September 5, 2003 - 12:53

Yes, my .htaccess looks like that. The fix worked perfectly for me. One thing, you'll need to move the two rules (administration and usr) to the top of your .htaccess file, before the other rules.

You did edit your common.inc file as mentioned above, didn't you?

Email me directly at boris AT bmannconsulting.com if you continue to have problems.

--
Boris Mann

Phew

teradome - July 9, 2004 - 22:43

Thanks, guys, I thought I was going to be screwed here. (On MediaTemple... they use the Ensim WebControl panels as well...)

New method

JonBob - July 10, 2004 - 00:54

Since the earlier comments, global URL aliasing has been made available in Drupal. You might check that out as an option to avoid having to patch code.

See the help in path.module.

path's conf.php sample doesn't work

teradome - October 11, 2004 - 06:47

Some help here would be appreciated since following the sample from path.module's help page does not work. I've since modified the sample for this case to:

function conf_url_rewrite($path, $mode = 'incoming') {
  if ($mode == 'incoming') { // URL coming from a client
    return preg_replace('!^administration/(.*)$!', 'admin/\1', $path);
  }
  else { // URL going out to a client
    $aliased = preg_replace('!^admin/(.*)$!', 'administration/\1', $path);
    if ($aliased != $path) { return $aliased; }
  }
}

This properly rewrites all /admin links as /administration, but it *obliterates all other links.* Every link that does not lead to the admin area is turned into a link to the root/homepage of the site, destroying all navigation. (cvs/4.5-rc)

buller? buller?

teradome - October 25, 2004 - 03:24

anyone?
i'd love to get this hack out of common.inc, but unless someone can help with getting this feature of path.module to a) support more than one rewrite, i.e. admin->administration AND user->usr and b) prevent it from destroying other links, it looks like i'm stuck hacking common.inc to get this done.

well, test

anders - October 28, 2004 - 19:21

I'm not really familliar with php so this is perl syntax, but you'll get the principle

if ( $path =~ /^admin\b/ ) { return $path =~ s/^admin\b/administration/ }
elsif ( $path =~ /^usr\b/ ) { return $path =~ s/^usr\b/user/ }
# ... and so on
# no need to change
else { return $path }

To See the help for path.module

Taran - November 13, 2004 - 16:50

People affected with this need the hack just to get to path.module (such as myself). I had this hack working well under 4.4.2, but now that I have upgraded to 4.5, it's not working.

So I'm looking now, in the path.module help.

To get as far as I am now, one has to:

(1) Hack the common.inc file as shown above.
(2) get the .htaccess file edited - not as shown, but like this:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteRule ^administration(.*)$ index.php?q=admin$1 [L,QSA]

  # Modify the RewriteBase if you are using Drupal in a subdirectory and the
  # rewrite rules are not working properly:
  #RewriteBase /drupal

  # Rewrite old-style URLS of the form 'node.php?id=x':
  #RewriteCond %{REQUEST_FILENAME} !-f
  #RewriteCond %{REQUEST_FILENAME} !-d
  #RewriteCond %{QUERY_STRING} ^id=([^&]+)$
  #RewriteRule node.php index.php?q=node/view/%1 [L]

  # Rewrite old-style URLs of the form 'module.php?mod=x':
  #RewriteCond %{REQUEST_FILENAME} !-f
  #RewriteCond %{REQUEST_FILENAME} !-d
  #RewriteCond %{QUERY_STRING} ^mod=([^&]+)$
  #RewriteRule module.php index.php?q=%1 [L]

  # Rewrite URLs of the form 'index.php?q=x':
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>

Note - the administration rewrite is ***immediately*** after 'Rewrite Engine on' on the third line. This is the result of the responses above.

Will write more as I work on this.

Folks, this is a really common problem and we need a better solution than "go downstairs, break down the door to the disused lavatory with the sign 'beware of jaguar' and look in the bottom drawer of the filing cabinet. The solution for this... whatever it is... needs to be in the installation guidelines so that anyone can have it on hand during installation.

I'll add it if I find a solution, but I would hope that someone else would as well. ;-)

Fixed.

Taran - November 13, 2004 - 17:16

Using the above hacks, I gained access to the administration pages on my site through this link in web browser:

http://www.?????.com/administration/path

This allowed me to gain access to the administration page for url aliases.

There, I added a url alias.

This alias was of form:

Existing system path: admin

New path alias: administration

I have verified that I can still access the web console provided by the ISP using

http://www.?????.com/admin

I then reverted common.inc and .htaccess to the original files that are downloaded.

It is important to note that it appears one must hack this to get to the url aliasing. Then one must un-hack this (or not) to assure a stable base.

I'll think on this a bit before I write up a feature request/bug report. I understand that the administration issue is somewhat inflexible for security reasons... but I also understand that ISPs commonly use admin for this purpose.

I'm thinking 'drupaladmin' may be a better url to use in the future...

sort of worked

teradome - November 25, 2004 - 00:18

Since standard url aliases are single page aliases only, this works for any link that goes straight to /admin but not for any that go to, say, admin/node.

I really, REALLY wish someone would just post a working example of this path.module global rewrite function that supported MORE THAN ONE PATTERN. We could easily take it from there.

Actually...

Taran - November 28, 2004 - 20:06

If you revert your files as I mentioned, the single page alias problem should go away.

no

teradome - November 29, 2004 - 23:26

no it doesn't. believe me, i've tried. i'm looking at it right now after adding url aliases and reverting common.inc and removing extra directives from .htaccess -- this simply isn't enough.

added: admin aliased to drupaladmin
added: user aliased to users

only the main administration page link is changed, the admin items underneath it are not (still /admin/settings for example). the user links on the posts themselves ("Submitted by...") are unchanged, for the same reason.

Fixed with httpd.conf rewrite

RoUS - January 10, 2007 - 17:08

I ran into this on my first setup of Drupal; the 'clean URLs test' kept varfing on /admin/settings. Someone gave me the hint, and sure enough I have an /admin alias in my global config.

The Drupal path module and alias setting (4.7.5) didn't help. I fixed this, though, by adding a single RewriteRule to my Drupal virtualhost stanza:

RewriteRule "^/admin(.*)" "/index.php?q=admin$1" [PT]

FWIW.

Easiest Fix

ShiftThis - March 2, 2005 - 22:40

There's no need to modify your common.inc or .htaccess to fix this problem. Simply do the following:

  1. First you need to have the Path Module enabled on your Drupal installation. You can access your module administration by typing in this address: http://www.yoursite.com/admin/modules and then enabling the Path Module (if you've already enabled the Path Module skip to next step)
  2. Go to http://www.yoursite.com/admin/path and add these url aliases:
    1. Existing System Path: admin New Path Alias: administration
    2. Existing System Path: user New Path Alias: usr
  3. That's it, your menu should work without any problems now

And although the rest of your administration links will still have the admin/ path they will all still work perfectly. So I really don't see how that could be any sort of problem.

Thank you, this worked

sifuhall - October 22, 2005 - 08:44

Thank you, this worked really well for me on my Ensim box.

This was an interesting

jyoseph - April 23, 2006 - 16:39

This was an interesting read. I used ShiftThis' instruction and it worked perfectly.

I use MediaTemple and they recommended putting my site in var/www/html/exampleurl.com instead of where my files are now in var/www/html/

This broke the site so I reverted back to var/www/html and used the fix noted by ShiftThis. That was perfect, thanks for the great support!

the method by shiftthis is

hanetworks - May 7, 2006 - 02:39

the method by shiftthis is not working in 4.7 though.

the /admin directory worked, but all subdirectories under /admin are not working.

I want a fix for this as well

Tigerstorm - June 12, 2006 - 22:59

I'm on Mediatemple and I'm sick n tired of their admin system not working..
Please can't anyone present a fix for 4.7 that sort this problem out!

I'm on 4.7 and it's working

jyoseph - June 14, 2006 - 16:40

I'm on 4.7 and it seems to be working ok for me. . . .

Under Existing system path:
I have admin (with no trailing slash)

I have administration set as the alternative path. Hope that helps . . .

This didn't work for me until...

Rob L - January 25, 2007 - 20:39

This wasn't working for me - when I submitted my log in, I was still sent to my host's user log in page.

I then switched off clean urls using SQL:
UPDATE variable SET value = 's:1:"0";' WHERE name = 'clean_url';
DELETE FROM cache;

This allowed me to log in using www.mysite.com/?q=user and I could navigate to www.mysite.com/?q=admin/path to set up the URL aliases as described above.

I then switched clean urls back on and now, fingers firmly crossed, I seem to be back in business.

ShiftThis Rocks!

Matt Dolphin - January 26, 2007 - 06:32

Thanks ShiftThis. Your post from March 2, 2005 Worked perfectly on Ensim with Drupal 5.0

Matt Dolphin
www.mattdolphin.com

Easiest Fix

peterdeitz - May 8, 2007 - 15:30

Well done ShiftThis. I was experiencing the same problem described with Ensim and Drupal 5.1.

I used the URL Aliasing module to create the new paths:
user -> usr
user/password -> usr/password
admin -> administration

The system works fine now. The best part is that the tabs in the user login pages automatically reflect the updated aliases.

For those who want to create the new aliases in Drupal 5.1, the address is:
http://www.yoursite.org/index.php?q=admin/build/path

Thanks for your help

ep4ma - May 21, 2007 - 23:46

Thanks to all those here. My host uses Ensim and this has got me out of trouble.

Change it in Ensim instead of in Drupal

kripaludas - December 21, 2007 - 01:15

I went the opposite route: I changed the redirects in Ensim instead.

Edit the following file:
/etc/httpd/conf/virtual/site** (where ** is the site number)

For instance, since I only have one site setup in Ensim (for a multi-site Drupal install), mine is site1 and thus I did:
vi /etc/httpd/conf/virtual/site1

Then look for all the RedirectMatch lines. You could either comment them out completely or I just changed the alias as bolded below. Instead of Ensim redirecting example.com/admin, it now redirects example.com/siteadmin. Likewise for example.com/siteuser

RedirectMatch ^/siteadmin/?$ https://000.000.000.000:19638/siteadmin/?ocw_login_domain=example.com
RedirectMatch ^/siteuser/?$ https://000.000.000.000:19638/siteuser/?ocw_login_domain=example.com

Make the changes and save then restart httpd.

There were two sections in my conf file that had to be changed for a total of four RedirectMatch lines changed.

There is a possibility that if you edit the site in Ensim, these edits may get overwritten, but I much prefer making the change in Ensim rather than in Drupal.

My experience with hosts

escoles - April 17, 2008 - 15:47

My experience with hosts using Ensim is that configurations frequently get over-written.

.htaccess and Path module

alienresident - January 17, 2008 - 02:07

I needed to redirect http://www.oldsite.com/admin to http://www.newsite.com/admin/
and use Clean Urls so that http://www.oldsite.com/ could be indexed by a search engine that doesn't like ?q=.

After much research I used a mixture of .htaccess and the path module

in the .htaccess I did the redirect
RedirectMatch permanent /admin$ http://www.newsite.com/admin/
RedirectMatch permanent /admin/$ http://www.newsite.com/admin/

Using the RedirectMatch with the $ to indicate the end of the line anchor.

http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#RewriteRule
http://httpd.apache.org/docs/1.3/mod/mod_alias.html#redirectmatch

It therefore doesn't redirect /admin/build etc.

Using the path module I changed admin to administration

seems to work

Path module fix for Admin directory problem

trevorulyatt - March 13, 2008 - 16:10

I have the path module enabled (one of the core optional modules, I think?). On all of my Drupal sites the url domain.com/admin/path produces a Page Not Found error.
Am I missing something here??
Cheers

 
 

Drupal is a registered trademark of Dries Buytaert.