2

I'm facing the following challenge:

I am setting up a homepage for our science department using OpenScholar, which is based on Drupal 6. From what I understand, it uses vsites so that many users can create personalized homepages on one OpenScholar installation.

I have set up OpenScholar on my server in the directory /var/www/example.com and it is served using a name-based VirtualHost on Apache2 that replies to the URL "example.com" ("example.com" is just a space holder).

When I created the homepage for my institute it is created at "example.com/example". The problem I am facing now is that I would like anyone calling "example.com" in their browser to end up at "example.com/example" without them even seeing "example.com/example" in their browser, in order to make the vsite my main site for "example.com". But I am not sure how to achieve this.

I have tried using Apache redirects/rewrites and also using the module "path redirect" and "global redirect" in Drupal, but it didn't work.

I would love to hear from someone on how this can be achieved.

------ EDIT ------

The answer by Tom Kirkpatrick did help, but I ran into a new problem. Here the setting I used:

  RewriteRule ^$ example/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
#  RewriteRule ^(.*)$ example/$1

I commented the last line due to the following: When I call example.com, I end up with example.com/example shown as example.com. But I have the problem that internal calls to page such as example.com/example/subpage is not changed to example.com/subpage. So if you continue browsing from example.com to a subpage in the browser you end up seeing example.com/example/subpage and not example.com/subpage, since that is the internal path that Drupal uses. That is also why I needed to comment the last line as this would rewrite example.com/example/subpage to example.com/example/example/subpage which does not exist. Or so I assume, because with it, it is not working. So is there some way to rewrite the path that the user sees in his browser from example.com/example/subpage (the internal path used by Drupal) to example.com/subpage without having to mess with the Drupal settings itself? I.e. to do it completely inside Apache? Thanks again!

  • 1
    Have you tried creating a symlink? Or changing the base url in your settings.php file? – chrisjlee May 17 '11 at 15:17
  • Well since the site is a Vsite it doesn't have have a subfolder in /sites to which I could do a symlink. The option using settings.php doesn't work either, because of the same reason. Since it applies to the root drupal-install. Or am I missing something? – packoman May 18 '11 at 19:04
  • Nope you're not missing anything. Symlinks would probably work. – chrisjlee May 18 '11 at 20:05
  • Ok, so could you perhaps elaborate a bit further on how I would do this? I am not sure how this should work, since I don't have physical directories for the subsites created by the vsite-module. It seems that Drupal manages this internally (through the vsite-module). I am still very new to these things, so please enlighten me. Thanks in advance! – packoman May 19 '11 at 7:32
2

So If I understand you correctly, you want to be able to access the site that is currently at http://www.example.com/example, by a simpler http://www.example.com

Create a .htaccess file in the webroot with the following:

Options -Indexes
RewriteEngine On
RewriteRule ^$ example/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ example/$1

Then, update your settings.php file to have the $base_url defined as: $base_url = 'http://example.com';

  • Hmm... after re-reading your question I'm not so sure I actually understand what it is you are trying to do! – Tom Kirkpatrick May 18 '11 at 21:56
  • Well in principle, that is what I want to do. However I'm not setting up Dupal in "standard" a multi-site setup, but using the vsite-module (which is used in OpenScholar). I am not sure how it works yet, but it doesn't create a directory in ./sites/ for each vsites, so that the idea from Chris using symlinks does not work(?). I am still very new to these things, so correct me if I am wrong, but it seems the apache rewrite rules/symlinks will only work if I actually have a physical directory for my subpage, right? – packoman May 19 '11 at 7:29
1

As I understand the question, the user is having a problem with removing a subdomain from the url. He's in need of a way to redirect any request to a subdomain site to a standard url. The following technique may help, as it provides a way to redefine the base url, based on an element appearing in the url structure. (Know that with Drupal, the base url is position -1, the first element after the base url is position 0, etc. So that if you want to set a condition to check for an element in position 0 of the url [www.base.com/position_0], as the code below does, you would write it to check for $path[0].

One of our Drupal 7 websites we maintain but did not develop has some code in the html.tpl.php that redirects pages with certain elements in the url position 0 to an alternate base url. I don't fully understand it but it's nice to know. Not sure if it's applicable to Drupal 6. Hope it helps somebody who needs a handy redirect method.

global $base_url;
$href = $base_url;
$path = drupal_get_path_alias($_GET['q']);
if ($path[0] == 'awards' OR strpos($_SERVER['HTTP_HOST'], 'awards') !== false) {
$head_title = $title . ' | Alternatesite.info';
$href = "http://www.alternate_site.info/";
$is_alternate_site = true;
}
else {
$href = $base_url;
$is_alternate_site = false;
}
  • I don't understand this answer either ... please improve it (it shows up in the "low quality posts" review queue ... – Pierre.Vriens Feb 9 '17 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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