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...

Comments

erikhopp’s picture

it is on the download page

Boris Mann _Old Blogger.com Account_’s picture

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

scott_’s picture

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.

Boris Mann _Old Blogger.com Account_’s picture

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

lowcarbkitten’s picture

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.

Boris Mann _Old Blogger.com Account_’s picture

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

teradome’s picture

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

jonbob’s picture

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.

teradome’s picture

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)

teradome’s picture

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.

anders’s picture

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 }
Taran’s picture

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. ;-)

Taran’s picture

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...

teradome’s picture

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.

Taran’s picture

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

teradome’s picture

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.

RoUS’s picture

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.

anuradhamudhigonda’s picture

This works great in local on windows , but does'nt work on online linux os

ShiftThis’s picture

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.

sifuhall’s picture

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

jyoseph’s picture

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!

hanetworks’s picture

the method by shiftthis is not working in 4.7 though.

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

Tigerstorm’s picture

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!

jyoseph’s picture

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 . . .

Rob L’s picture

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.

mdolphin’s picture

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

Matt Dolphin
www.mattdolphin.com

peterdeitz’s picture

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

ep4it’s picture

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

ad8five’s picture

Nice work.

kripaludas’s picture

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.

escoles’s picture

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

alienresident’s picture

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

trevorulyatt’s picture

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

ashiwebi’s picture

How I can change the admin url for example

http://www.example.com/?q=admin

to

http://www.exmaple.com/?q=xyz

Is the .htaccess is the only solution or we have to write code as the drupal api suggest to use function custom_url_rewrite.

Please suggest me the easy way.

ashiwebi’s picture

I found one code for customising the admin url

function custom_url_rewrite($op, $result, $path) {

if ($op == 'alias') {
if (preg_match('|^admin(/{0,1}.*)|', $path, $matches)) {
return 'config'. $matches[1];
}
}

if ($op == 'source') {
if (preg_match('|^config(/{0,1}.*)|', $path, $matches)) {
return 'admin'. $matches[1];
}
}

return $result;

}

The problem with the code is that it creates the url but it shows the login at both the location config as well as admin location.Please suggest the solution for admin only so that user are not able to access the admin login page.

andrewsuth’s picture

The above solution uses custom_url_rewrite which has been separated to:
custom_url_rewrite_inbound
custom_url_rewrite_outbound
for Drupal 6.

Has anyone tried to implement the same code using these new functions for Drupal 6?

mpwi’s picture

The following works for drupal 6: (Just add it to the end of the settings.php file)

function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
  global $user;

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

  if (preg_match('|^administration(/.*)|', $path, $matches)) {
    $result = 'admin'. $matches[1];
  }
  if ($path == 'administration') {
    $result = 'admin';
  }
  if (preg_match('|^usr(/.*)|', $path, $matches)) {
    $result = 'user'. $matches[1];
  }
  if ($path == 'usr') {
    $result = 'user';
  }
}
rkudyba’s picture

This suggestion doesn't block or send the user a 404 page if they "guess" domain.com/admin. Any way to do that?

ad8five’s picture

Nice work.

raphael apard’s picture

I have created a small module doing this for D7 : Rename admin paths. (I need some reviews so ... ;)

Raphael