Hello,

You must be going carzy how to setup a multiple subdomain
(drupal1.Yourdomain.com, drupal2.Yourdomain.com) drupal installation with clean url and you do not want to mess with symlink, since you do not want extra directories being here and there even if it points back to the main directory. Well lots of post claiming how to do this simple thing but if it would be as clear as it claimed then why are the post so long as you do not even want to read through?

I was messing with symlink and then I have ended up creating unlimited directories nesting into each other.

Here is what you want:

http://Yourdomain.com (Your Main Drupal Installation File)
-http://drupal1.Yourdomain.com
-http://drupal2.Yourdomain.com

Requirements:
1. Full access to your server administration. I use putty telnet. (Apache, Debian Linux)
2. Database setups. I have 3 databases, each installation uses different database. (no pre extension messings) I have mySQL database and I use phpmyadmin to configure access and database tables.
3. You have a domain name which points to http://Yourdomain.com or http://www.Yourdomain.com (www do not matter)

Steps:

1. You create an installation to your public directory using FTP access. In this example the server directory is /www/yourdomain.com is the directory where you install the drupal system ((www.)Yourdomain.com points to this directory)

2.Access /www/yourdomain.com/sites with your FTP client

3. Copy the default folder into the same directory and rename the copy to (do it all over as many subdomains you would like). In this example:
a.)drupal1.Yourdomain.com
b.)drupal2.Yourdomain.com

4. Go to /www/yourdomain.com/sites/drupal1.Yourdomain.com with your FTP

5. Access /www/yourdomain.com/sites/drupal1.Yourdomain.com/settings file and rewrite the following line with your database access information:
$db_url = 'pgsql://username:password@localhost/databasename';

6. Save and upload the new file.

7. Redo #5 with :/www/yourdomain.com/sites/drupal2.Yourdomain.com/settings

8. Access your server host settings, all server configurations are different, but mine is located in
/etc/apache/virtualhosts.conf

insert the following lines:


DocumentRoot /www/yourdomain.com
ServerName drupal1.Yourdomain.com
ErrorLog /var/log/apache/Yourdomain.com-error.log
CustomLog /var/log/apache/Yourdomain.com-access.log combined


DocumentRoot /www/yourdomain.com
ServerName drupal2.Yourdomain.com
ErrorLog /var/log/apache/Yourdomain.com-error.log
CustomLog /var/log/apache/Yourdomain.com-access.log combined

Assume that you have this already:


DocumentRoot /www/yourdomain.com
ServerName Yourdomain.com
ErrorLog /var/log/apache/Yourdomain.com-error.log
CustomLog /var/log/apache/Yourdomain.com-access.log combined

9. Save your modification and restart your server. (There are other way to add this inserted through .haccess file but this is not how I did it.)

10. Create a file and name it .htaccess.
Place this code into the file:

//////////////////////////////////////////////////////////////////////////////////////////////
#
# Apache/PHP/Drupal settings:
#

# Protect files and directories from prying eyes.

Order allow,deny

# Don't show directory listings for URLs which map to a directory.
Options -Indexes

# Follow symbolic links in this directory.
Options +FollowSymLinks

# Customized error messages.
ErrorDocument 404 /index.php

# Set the default handler.
DirectoryIndex index.php

# Override PHP settings. More in sites/default/settings.php
# but the following cannot be changed at runtime.

# PHP 4, Apache 1.

php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0

# PHP 4, Apache 2.

php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0

# PHP 5, Apache 1 and 2.

php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0

# Requires mod_expires to be enabled.

# Enable expirations.
ExpiresActive On
# Cache all files for 2 weeks after access (A).
ExpiresDefault A1209600
# Do not cache dynamically generated pages.
ExpiresByType text/html A1

# Various rewrite rules.

RewriteEngine on

# If your site can be accessed both with and without the 'www.' prefix, you
# can use one of the following settings to redirect users to your preferred
# URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
#
# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# adapt and uncomment the following:
# RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
# RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
#
# To redirect all users to access the site WITHOUT the 'www.' prefix,
# (http://www.example.com/... will be redirected to http://example.com/...)
# adapt and uncomment the following:
# RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
# RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

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

# 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 current-style URLs of the form 'index.php?q=x'.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

# $Id: .htaccess,v 1.81.2.3 2007/09/21 12:24:22 drumm Exp $

/////////////////////////////////////////////////////////////////////////

Do not ask me what this is, some url rewrite conditions.

11. Upload this to /www/yourdomain.com/.htaccess with your FTP client

12. Now you can visit http://drupal1.Yourdomain.com or http://drupal2.Yourdomain.com or http://(www.)Yourdomain.com

I hope it works for you. I tested and it sure worked for me w clean URL.

If it does not then try to modify the .htaccess file and place this code into:
RewriteBase /yourdomain.com

Thats the only thing which can prevent this to work.

Best regards,
Gabor Vojnar
http://www.weboldal.biz

Comments

omnyx’s picture

my question is how to have many drupal installations - for example I have a drupal website at www.mysite.com
but i want to separately install drupal in subdomain.mysite.com
the problem is that .htaccess looks like this

RewriteEngine on
RewriteRule (.*) drupal/$1 [L]

since original drupal installatio is in public_html/drupal
how to let apache know not to apply the rule for links that are of the subdomain.mysite.com form?

thanks