My main Drupal installation is in a folder under main directory(public_html/drupalsite).

- I created a subdomain via Cpanel. Set Document Root as public_html/drupalsite.

- I created a DB for subdomain..

- Then created a directory for my subdomain under my main Drupal installation:

drupalsite/sites/subdomain.drupalsite.com

- Copied settings.php from drupalsite to drupalsite/sites/subdomain.drupalsite.com and changed DB settings to make it match its DB.

- Created a symlink.php with this code(and run it by visiting via browser):

<?php symlink('/home/myhostaccount/public_html/drupalsite', 'subdomain.drupalsite.com'); ?>

- I visited subdomain.drupalsite.com, it gave error then i visited subdomain.drupalsite.com/install.php and made installation without error.

Everything was normal till this step. Then i wanted to enable Clean URLs for subdomain and tried a lot of variation on .htaccess(I read tens of page about this, saw lots of different examples, tried most of them).

Then I deleted directory that Cpanel created for subdomain when i noticed there was a complete Drupal installation in it. And i managed to lost my main site. Because all files under main site was deleted(except directories). It seems symlink settings was wrong. :(

It took more than 2 hours to reinstall(i deleted everthing except sites folder, uploaded drupal 7.12 files again and updated) and fix it. (It seems OK now but i am still suspicious about it might create problems in future because of this mistake.)

My question is:

How to set Clean URLs for a multi site subdomain which base Drupal installation is in a folder, not in main directory(eg. instead of public_html, it is installed to public_html/drupalsite)?

I have read tons of documents, tried a lot but could not manage. I need a tested, working solution. And i don't want to take the risk of losing my main installation.

Thanks in advance.

Comments

Jaypan’s picture

As long as the main installation is able to use clean URLs, I've never had an issue with putting the subdomain on clean URLs. They use the same .htaccess file in the webroot directory, so if your main domain has clean URLs enabled, your subdomain should as well. So is your .htaccess file in the webroot?

As for your process, I don't understand the purpose of the symlink you have created - I've never needed to do this before. Maybe this has something to do with your problem?

ErgunK’s picture

I read all of these and tried most of them: http://www.google.com/search?hl=tr&sclient=psy-ab&q=drupal+clean+URL+for...

If you could share the steps you followed and the right settings that work i would appreciate.


Mediasaur | http://www.mediasaur.com/en | http://twitter.com/mediasaur


Before asking for help, please read this http://slash7.com/2006/12/22/vampires/ and don't be a "Help Vampire". :)
Jaypan’s picture

Here is how I create a multi-site subdomain:

1) I edit my httpd.conf file to set up the new subdomain, pointing it at the root of the current install.
2) I create a folder in /sites with the name of the subdomain. Ex: sub.example.com
3) I copy /sites/default/default.settings.php to /sites/sub.example.com
4) I create a new database for the subdomain (or you can use the current one with a prefix)
5) I access the subdomain through my browser, and install as normal.

Clean URLs just works (as long as there is an .htaccess file in the webroot).

Of course, you are in a different environment, which is why it may not be working for you. Maybe you need to make a step I don't.

ErgunK’s picture

Thank you for sharing. My site is in a shared hosting(Hostmonster) and my main site is not installed directly to public_html, it is in a folder public_html/mydrupalsite.

I used this .htaccess setting to make it act like it is installed public_html(This .htaccess file is in root, in public_html):

# Use PHP5CGI as default
AddHandler fcgid-script .php


# .htaccess main domain to subdirectory redirect

RewriteEngine on
# Change yourdomain.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?mydrupalsite.com$ [NC]
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/mydrupalsite/
# Don't change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /mydrupalsite/$1
# Change yourdomain.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?mydrupalsite.com$
RewriteRule ^(/)?$ mydrupalsite/index.php [L]

And then, under my public_html/mydrupalsite folder, i put this .htacces to make Clean URLs work(And it works):

# Source of this: http://drupal.org/node/121834


#
# Apache/PHP/Drupal settings:
#

# Protect files and directories from prying eyes.
<FilesMatch "(\.(engine|inc|install|module|sh|.*sql|theme|tpl(\.php)?|xtmpl)|code-style\.pl|Entries.*|Repository|Root)$">
  Order deny,allow
  Deny from all
</FilesMatch>

# Set some options.
Options -Indexes
# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymLinks
Options +SymLinksIfOwnerMatch

# 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
<IfModule mod_php4.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
</IfModule>

# PHP 4, Apache 2
<IfModule sapi_apache2.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
</IfModule>

# PHP 5, Apache 1 and 2
<IfModule mod_php5.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
</IfModule>

# Reduce the time dynamically generated pages are cache-able.
<IfModule mod_expires.c>
  ExpiresByType text/html A1
</IfModule>

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on

  # If your site can be accessed both with and without the prefix www.
  # you can use one of the following settings to force user to use only one option:
  #
  # If you want the site to be accessed WITH the www. only, adapt and uncomment the following:
  # RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
  # RewriteRule .* http://www.example.com/ [L,R=301]
  #
  # If you want the site to be accessed only WITHOUT the www. , adapt and uncomment the following:
  # RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
  # RewriteRule .* http://example.com/ [L,R=301]


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

  # 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 rules for static page caching provided by the Boost module
  # BOOST START
  <IfModule mod_mime.c>
  AddCharset utf-8 .html
  </IfModule>
  RewriteCond %{REQUEST_URI} !^/cache
  RewriteCond %{REQUEST_URI} !^/user/login
  RewriteCond %{REQUEST_URI} !^/admin
  RewriteCond %{HTTP_COOKIE} !DRUPAL_UID
  RewriteCond %{REQUEST_METHOD} ^GET$
  RewriteCond %{QUERY_STRING} ^$
  RewriteCond %{DOCUMENT_ROOT}/cache/%{SERVER_NAME}/0/%{REQUEST_URI} -d
  RewriteCond %{DOCUMENT_ROOT}/cache/%{SERVER_NAME}/0/%{REQUEST_URI}/index.html -f
  RewriteRule ^(.*)$ cache/%{SERVER_NAME}/0/$1/index.html [L]
  RewriteCond %{REQUEST_URI} !^/cache
  RewriteCond %{REQUEST_URI} !^/user/login
  RewriteCond %{REQUEST_URI} !^/admin
  RewriteCond %{HTTP_COOKIE} !DRUPAL_UID
  RewriteCond %{REQUEST_METHOD} ^GET$
  RewriteCond %{QUERY_STRING} ^$
  RewriteCond %{DOCUMENT_ROOT}/cache/%{SERVER_NAME}/0/%{REQUEST_URI}.html -f
  RewriteRule ^(.*)$ cache/%{SERVER_NAME}/0/$1.html [L]
  # BOOST END

  # 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]
</IfModule>

# $Id: boosted.txt,v 1.4 2006/12/05 10:39:19 arto Exp $

With this settings /mydrupalsite and Clean URLs works well. But i could not manage to create subdomain multisites' Clean URLs work. That is my problem.


Mediasaur | http://www.mediasaur.com/en | http://twitter.com/mediasaur


Before asking for help, please read this http://slash7.com/2006/12/22/vampires/ and don't be a "Help Vampire". :)
Jaypan’s picture

Why don't you put a normal .htaccess file in your webroot, and point both the main domain, as well as the subdomain, at your subfolder? You shouldn't need a tweaked .htaccess file.

I was doing this for quite a while on a subdomain until recently. Main domain:
/home/account_name/public_html

Add-on domain:
/home/account/name/public_html/addon_domain

Sub domain:
/home/account/name/public_html/addon_domain

As you can see, both the add on and the subdomain were in a sub folder of the main domain (which is essentially the same thing you have going on). I had one .htacccess located at:
/home/account/name/public_html/addon_domain/.htaccess

This .htaccess folder was a normal Drupal .htaccess.

ErgunK’s picture

It doesn't work if i dont add modified .htaccess files.

I am confused; sub domains are not addon domains, they don't have domain names?

My structure:

Main Drupal installation is in this folder:
/home/account/name/public_html/mydrupalsite

Subdomain files are in this folder:
/home/account/name/public_html/mydrupalsite/sites/subdomain.mydrupalsite.com


Mediasaur | http://www.mediasaur.com/en | http://twitter.com/mediasaur


Before asking for help, please read this http://slash7.com/2006/12/22/vampires/ and don't be a "Help Vampire". :)
Jaypan’s picture

I don't know what to say. It's too hard to debug what you have going on by text. I can only tell you what I've done that works. Sorry.

ErgunK’s picture

Jaypan thank you for your interest, sharing and time. I found the solution and will share below.


Mediasaur | http://www.mediasaur.com/en | http://twitter.com/mediasaur


Before asking for help, please read this http://slash7.com/2006/12/22/vampires/ and don't be a "Help Vampire". :)
ErgunK’s picture

I finally solved the problem; thanks to Mile23 for this article: Wiki Page: Multisites Using Drupal 7

Solution steps for me(Additional to first 5 steps in the first post of me in this page):

- Instead of using symlinks, i copied example.sites.com as sites.php and added the line end of it(This solved redirection problem):

$sites['subdomain.drupalsite.com'] = 'subdomain.drupalsite.com';

- In the .htaccess in the drupalsite, i made sure the line below was uncommented(If it was commented with # it would not work already.):

RewriteBase /drupalsite

And added this line(This solved Clean URLs problem:)

RewriteBase /

Hope these works for you too.


Mediasaur | http://www.mediasaur.com/en | http://twitter.com/mediasaur


Before asking for help, please read this http://slash7.com/2006/12/22/vampires/ and don't be a "Help Vampire". :)
leonkarthi’s picture

Hi , i tried most of the option in the drupal community to solve this problem. But don't know know which sequence i had done the wrong changes. Please let me know , how to make the clean url working for my subsite(for main site, its working perfectly)
this is how my .htaccess of drupal7 is,

# Various rewrite rules.

RewriteEngine on

# Block access to "hidden" directories whose names begin with a period. This
# includes directories used by version control systems such as Subversion or
# Git to store control files. Files whose names begin with a period, as well
# as the control files used by CVS, are protected by the FilesMatch directive
# above.
#
# NOTE: This only works when mod_rewrite is loaded. Without mod_rewrite, it is
# not possible to block access to entire directories from .htaccess, because
# is not allowed here.
#
# If you do not have mod_rewrite installed, you should remove these
# directories from your webroot or otherwise protect them from being
# downloaded.
RewriteRule "(^|/)\." - [F]

# 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/...)
# uncomment the following:
# RewriteCond %{HTTP_HOST} !^www\. [NC]
# RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [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/...)
# uncomment the following:
# RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
# RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]

# Modify the RewriteBase if you are using Drupal in a subdirectory or in a
# VirtualDocumentRoot and the rewrite rules are not working properly.
# For example if your site is at http://example.com/drupal uncomment and
# modify the following line:
RewriteBase /drupal7

#
# If your site is running in a VirtualDocumentRoot at http://example.com/,
# uncomment the following line:
# RewriteBase /

# Pass all requests not referring directly to files in the filesystem to
# index.php. Clean URLs are handled in drupal_environment_initialize().
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
# RewriteRule ^ index.php [L]
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
# Rules to correctly serve gzip compressed CSS and JS files.
# Requires both mod_rewrite and mod_headers to be enabled.

# Serve gzip compressed CSS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.css $1\.css\.gz [QSA]

# Serve gzip compressed JS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.js $1\.js\.gz [QSA]

# Serve correct content types, and prevent mod_deflate double gzip.
RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]

ached unless they explicitly send cache
# headers themselves. Otherwise all scripts would have to overwrite the
# headers set by mod_expires if they want another caching behavior. This may
# fail if an error occurs early in the bootstrap process, and it may cause
# problems if a non-Drupal PHP file is installed in a subdirectory.
ExpiresActive Off

----------------------------------------------------------------------------------------
and this is how my http.config file is


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


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

Re-write module is enabled. Working fine for my main website.

My main site is /var/www/alpha/drupal7
i have made a softlink for my subsite as /var/www/alpha/drupal7/firstweb

The Scenario is , i have main site in seprate DB, then i took backup of mainweb site DB and loaded into second website. Then i made required changes in the second website and everything was working good,except when i was trying you to enable clean url . If i change the base url as /drupal7/firstweb (which is my second website path), then the clean url is working for second website. but the thing is , it stops working for main website since then. Kindly let me know what would have went wrong or to be down or whatsoever, please help me out to go pass this...

Thanks a lot in advance!!

leonkarthi’s picture

Hi Guys, Found answer for my drupal problem. Found the Solution from,

http://drupal.org/node/15365

Helped Well for me after a long search.

Need to give the subsite rule-conditons ahead of already existing rule conditons(which will be used for main site).

SO the structure will be simialar to

sub site rule conditions
main site rule conditions

in my case, what i did was, before the line RewriteRule "(^|/)\." - [F] (see my above post for the line),
i added lines as ,

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

then followed by

RewriteRule "(^|/)\." - [F] (the line i mentioned above)
then other commands.

Note: THis is how i solved the issue. And have posted this solution asap when i found it to help others. Was Struggling for the output about 3 days(including 1 full days)

Cheers!! :-)