0

In my installation, I'm utilizing Drupal's awesome capability to run on multiple subdomains using one code base. Each subdomain has its own database. So, I only need to have a static page on the main domain (root) but Drupal running on subdomains.

How do I do that? I know that I could modify the .htaccess file to make it look up for index.html first, but that would affect the subdomains.

Thanks.

1

You can solve this one using a RewriteRule in your .htaccess file. What you basically will do is check if the request is destined for your main domain (both with and without the www), and if so, tell Apache to go fetch the files from somewhere else. All this is done on the server-side, so the browser doesn't see a thing about this.

For the example below, I assume that Drupal is installed in /var/www. If it's installed somewhere else, update all occurrences of /var/www below.

  1. Create a new directory /var/www/static_main_domain. This directory will contain the static content of your main domain.
  2. Add the following lines of code to your .htaccess file (preferably immediately behind the RewriteEngine On):

# Check if the request is destined for www.yourdomain.com OR RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com [NC,OR] # Check if the request is destined for yourdomain.com RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC] # If so, go get the requested files from the static_main_domain subdirectory. RewriteRule ^(.*)$ static_main_domain/$1 [L,QSA]

For more info, check this: http://httpd.apache.org/docs/current/mod/mod_rewrite.html

  • Exactly what I needed. Thanks a bunch! The other answer is good, but I find modifying .htaccess is less intrusive. I just need to save a backup, so I'll never lose this. – user173457 Aug 30 '14 at 4:40
0

Most solid way is to change configuration of your web server. Something like:

<VirtualHost *:80>
  DocumentRoot /var/www/static_page
  ServerName example.com
</VirtualHost>

<VirtualHost *:80>
  DocumentRoot /var/www/drupal_multisite
  ServerName other.example.com
  ServerAlias *.example.com
</VirtualHost>

See Virtualhost For Wildcard Subdomain and Static Subdomain for more server-oriented answers.

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.