D6 Multi-site Symlink Works But Causing Infinite URL Subpath and Recursive Server Folder

rCharles's picture

I've searched and searched and searched drupal.org multi-site documentation, forums, issues etc along with the web and can't find answer to my conundrum on subpath (URL path) site installs with symlinks. Sub-domains are not an issue.

While I can get subpath (URL path) site installs to work usng symlink with no .htaccess mods, the symlink creates both infinite URL subpaths and infinite server subfolders. This is driving me mad after hours and hours of trying to find something comprehensive on symlinks and specifically on about drupal multi-site. I'd like to do client betas and prototypes in a subpath but this has me stalled.

  1. Multi-site main site: No Issues
    Cpanel Addon Domain set to server files folder
  2. Multi-site Sub-domain sites: No Issues
    Cpanel Addon Domain set to server files folder
    And proper sites folder
  3. Or, subdomain NOT as part of multi-site: No Issues
    Cpanel Addon Domain set to server files folder

  4. Multi-site Sub-folder sites: Works but with concerns
    Cpanel settings not required, but did create proper sites folder
    then followed with SSH command via Putty to create a symlink:
        ln -s ~/public_html/d6core ~/public_html/d6core/pathtest

    Right away http://site.com/pathtest worked in the browser, install modules and all, with no need to alter .htaccess. At first, I was quite pleased, happy and thought how simple... but know here's my concern and confusion: Infinite URL path and server folders.

    • From the browser, the URL works as infinite subpath:
          etc, etc
    • From server file manager or Putty SSH "ls -1" folders are also infinite:
         pathtest@ (the symlink)
            pathtest@ (the symlink)
                includes/ misc/ modules/ pathtest@ profiles/ scripts/ sites/ themes/
                    includes/ ...  pathtest@ ... themes/
                         includes/ ...  pathtest@ ... themes/

I've tried other iterations of above such as ln -s . pathtest from the public_html/d6core folder. Should I be using Alias command?

Thanks for any help. No doubts this would help many others too.

NOTE: When I asked this question, I was not clear that this was a D6 setup even if I did show     /public_html/d6core in the write up. Aside, this is about a symlink recursion with complete install/instance of Drupal as a domain/path note subdomain.domain ie drupal1/drupal2/.. drupal1/drupal3/.. Some answers failed to notice that.


Folder on server

joyseeker's picture

Did you delete the folder after you created the subdomain?

The process is:

create a subdomain

delete the folder on the server

then run the symlink code

I have my multisites up without any tinkering with htaccess...

Again, not a subdomain - a URL path

rCharles's picture

Again, not a subdomain. Subdomains are not the issue.

When you create a symlink do you get infinite file folders and infinite URL path recursion?

Yes ,I have same problem in my website

shabanbi's picture

I have created symlinks for multisite subfolders
like ex :- "http://website.com/subfolder"
i have created symlinks "ln -s . subfolder"
then after i created folder website.com.subfolder in public_html/sites/ this path . My multisites working fine but it taken infinite url paths for every subfolder like


Please advise me how to avoid this infinite url path recursion in drupal 7 ?


.htaccess for multi-site subURLpaths (subfolders)

rCharles's picture

I've found Drupal's core/root apache .htaccess file needs additions to handle instances of subURLpath multisites.

For URL:

In Folder:: ../sites/site.com.multisiteURLpath

Try this after the #rewritebase (leave this commented) in settings.php:

RewriteCond %{REQUEST_URI} ^/multisiteURLpath/multisiteURLpath
RewriteRule ^/multisiteURLpath/index.php [L]

This does not resolve infinite folder recursion seen from FTP or Control Panel File Managers due to the symlink but I believe that is less an issue.

Multisite is easier than you

Mile23's picture

Multisite is easier than you think. The .htaccess is not wrong.

1) You set all domains and subdomains to use the same docroot: the main Drupal directory.

2) Then you arrange the folders with their domain names under /sites.

3) Then Drupal figures out which /sites subfolder to use based on the request.

So for example.com you'd put the site-specific stuff in /sites/default or /sites/example.com

For thingie.example.com you'd put the site-specific stuff in /sites/thingie.example.com

For thingie.example.com/some/path you'd put the site-specific stuff in /sites/thingie.example.com.some.path

Then Drupal figures out which to use based on the domain name and path present in the request.

If you're using symbolic links, you might be over-thinking it. :-)

See default.settings.php for some instruction.

Re: Multisite is easier than you

mstrelan's picture

If you're using symbolic links, you might be over-thinking it. :-)

Not if you want subdirectories as separate instances, rather than subdomains.

I have multiple domains with

dpatte's picture

I have multiple domains with unique domain names using multisite. It does NOT use symlinks.

No Symlinks Needed

Lakeside's picture

Didn't use symlinks to set up multisites on a virtual server. Heard about symlinks and thought maybe there was an advantage in using it, so tried it. Gave up on the idea because I couldn't get it working. Went back to the easy-peeze approach. There must be a reason for using symlinks, just don't know what it is.

@dpatte and @Lakeside

mstrelan's picture

Symlinks are needed for SUBDIRECTORIES as separate sites. For example www.example.com/site1 and www.example.com/site2 rather than site1.example.com. Although please correct me if I'm wrong.

If example.com is the root

Lakeside's picture

If example.com is the root site, the other domains are all in the site directory, i.e. simple.com, sample.com, whiz.com, etc.

Is that what you are talking about?

No, symlinks are NOT needed...

tsssystems's picture

for subdomains, subdirectories, or any site set up at all. Looked into symlinks myself in desperation, but then I realized they're not necessary for most applications. Probably the only time they might be is if there was some security implication, which I recall reading about in someone's blog. Didn't apply to me, so I'm not using them.

I agree with those who say you may be over-thinking it. It's easy enough to do, because most of the documentation has been written by those who know the process so well, that they either don't explain in detail or leave out some steps they don't really think about because it's so second-nature to them. I find this is true with most Linux / open-source documentation - period. Had me scratching my head for days the first time I tried to set up a multi-site as a local dev environment.

Drupal does perfectly fine NOT using symlinks. Just follow the comments in settings.php, which tell you that what you're trying to do is EXACTLY what settings.php was designed for, without needing symlinks.

I quote:

* For example, for a fictitious site installed at
* http://www.drupal.org/mysite/test/, the 'settings.php'
* is searched in the following directories:
* - sites/www.drupal.org.mysite.test

BINGO! Shows you that if you name your folders in the sites/ folder correctly, Drupal will find it.

If that's not a perfect example of not needing a symlink, I don't know what is. The ONLY thing I see is that you've (apparently) installed Drupal in a folder above the web root your server, NOT in the public_html directory. That's fine, I've done that too, but you need to make sure your DNS is pointing to THAT (d6core) directory.

http://site.com has to point to: public_html/d6core/, not just public_html/. That's all. If that's correct, you can make a site at any subfolder you want, symlinks not required. Your folder at:
will be reached from the URL http://site.com/pathtest . Delete the symlinks.

18 separate sites on 3 code bases...

Debugging why it won't work without symlinks

mstrelan's picture


I completely understand what you're saying, and I thought that it should work like you said, so I've done a few tests, perhaps you can help me make sense of them. Please note I've replaced the actual domain with "example.com" and actual subdirectory with "subdirectory". I used real values to perform these tests but did a simple find/replace on the output.

  1. Check that the symlink exists, and that there is an appropriate settings.php file.

    root@host2 [/home/mstrelan/public_html]# ls -l | grep subdirectory
    lrwxrwxrwx  1 mstrelan mstrelan     1 Feb 28 10:14 subdirectory -> ./

    root@host2 [/home/mstrelan/public_html]# ls -l sites/example.com.subdirectory/
    total 16
    drwxr-xr-x  3 mstrelan mstrelan 4096 Feb 15 10:27 ./
    drwxr-xr-x  9 mstrelan mstrelan 4096 Feb 28 10:26 ../
    drwxrwxr-x 10 mstrelan mstrelan 4096 Dec  4 15:57 files/
    -rw-r--r--  1 mstrelan mstrelan 1995 Feb 28 10:26 settings.php
  2. See if we get a HTTP/1.1 200 OK response.

    root@host2 [/home/mstrelan/public_html]# curl -I http://example.com/subdirectory/
    HTTP/1.1 200 OK
    Date: Thu, 28 Feb 2013 00:18:18 GMT
    Server: Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/1.0.0-fips mod_bwlimited/1.4
    X-Powered-By: PHP/5.2.17
    X-Drupal-Cache: HIT
    Etag: "1362010659-0"
    Content-Language: en
    X-Generator: Drupal 7 (http://drupal.org)
    Link: <http://example.com/subdirectory/>; rel="shortlink",<http://example.com/subdirectory/>; rel="canonical"
    Cache-Control: public, max-age=0
    Expires: Sun, 19 Nov 1978 05:00:00 GMT
    Vary: Cookie,Accept-Encoding
    Last-Modified: Thu, 28 Feb 2013 00:17:39 GMT
    Content-Type: text/html; charset=utf-8
  3. Remove the symlink and try again.

    root@host2 [/home/mstrelan/public_html]# rm subdirectory
    rm: remove symbolic link `subdirectory'? y

    root@host2 [/home/mstrelan/public_html]# curl -I http://example.com/subdirectory/
    HTTP/1.1 301 Moved Permanently
    Date: Thu, 28 Feb 2013 00:18:40 GMT
    Server: Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/1.0.0-fips mod_bwlimited/1.4
    X-Powered-By: PHP/5.2.17
    X-Drupal-Cache: MISS
    Expires: Sun, 19 Nov 1978 05:00:00 GMT
    Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0
    ETag: "1362010720"
    Last-Modified: Thu, 28 Feb 2013 00:18:40 GMT
    Location: http://example.com/subdirectory
    Content-Type: text/html
  4. Hmm, it's redirecting to the same URL but with the slash removed. Probably due to globalredirect "deslash" option. Check the response of the URL without the slash.

    root@host2 [/home/mstrelan/public_html]# curl -I http://example.com/subdirectory
    HTTP/1.1 404 Not Found
    Date: Thu, 28 Feb 2013 00:18:58 GMT
    Server: Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/1.0.0-fips mod_bwlimited/1.4
    X-Powered-By: PHP/5.2.17
    X-Drupal-Cache: MISS
    Etag: "1362010738-0"
    Content-Language: en
    Cache-Control: public, max-age=0
    Expires: Sun, 19 Nov 1978 05:00:00 GMT
    Vary: Cookie,Accept-Encoding
    Last-Modified: Thu, 28 Feb 2013 00:18:58 GMT
    Content-Type: text/html; charset=utf-8

HTTP/1.1 404 Not Found :(

I then disabled globalredirect and tested again, but got another 404.

tsssystems's picture

but two things struck me about this.

1) Did you clear your cache between tests? If not, it's no surprise that you got a 404 error.

2) Where is the actual DNS for "example.com" pointing to? Now it looks like you've installed drupal in the public_html directory, and that that's where you had the symlink. I know you like to keep the real url hidden, but without knowing the real directory structure on the web server and where your DNS is really pointing to it's impossible to troubleshoot. In your earlier post it appeared that you had installed Drupal one level up from your web root; here it looks like Drupal is installed at the web root. DNS won't point to both directories...

If you're not familiar with drush, you should check it out. You can do many things with it, including clear your caches from the command line. Very handy.

Not sure what gave you the

mstrelan's picture

Not sure what gave you the impression that I had Drupal installed outside of the web root. I am very familiar with drush. The reason I'm testing with cURL is because it's an easy way to paste the headers on g.d.o. I could've opened it in my browser and uploaded screenshots, but cURL seemed easier.

To make it easier to demonstrate I've replicated the situation on an fresh installation of Drupal which you can see at http://michaelstrelan.com.au. I tried to set up a multisite installation of it at http://michaelstrelan.com.au/example which you can see raises a 404 not found error.

This is how I've got my sites directory set up.

root@host3 [/home/mstrelan/public_html]# ls -l sites
total 28
drwxr-xr-x  5 mstrelan mstrelan 4096 Feb 28 14:47 ./
drwxr-xr-x 10 mstrelan mstrelan 4096 Feb 28 14:43 ../
drwxr-xr-x  4 mstrelan mstrelan 4096 Feb 28 14:37 all/
drwxr-xr-x  3 mstrelan mstrelan 4096 Feb 28 14:41 default/
-rw-r--r--  1 mstrelan mstrelan 2365 Feb 28 14:37 example.sites.php
drwxr-xr-x  2 mstrelan mstrelan 4096 Feb 28 14:47 michaelstrelan.com.au.example/
-rw-r--r--  1 mstrelan mstrelan  904 Feb 28 14:37 README.txt
root@host3 [/home/mstrelan/public_html]#

I have cleared the cache of both michaelstrelan.com.au and michaelstrelan.com.au.example

root@host3 [/home/mstrelan/public_html]# drush --uri=default cc all
'all' cache was cleared in /home/mstrelan/public_html#default              [success]
root@host3 [/home/mstrelan/public_html]# drush --uri=michaelstrelan.com.au.example cc all
'all' cache was cleared in                                                 [success]

Multisite in three easy

Mile23's picture

Multisite in three easy steps:

0) Understand why you want a multisite setup. The reason you want a multisite setup is so you can have one codebase with a number of different configurations, selected by domain and path. You could also have many Drupal installation, one per domain, and not have to figure out how multisite works. :-)

1) Your http server's docroot for all multisite sites is the Drupal root. Drupal will look at the request to figure out which site to use. Make a default site that works for one domain name and then leave the server's docroot configuration alone.

2) Make /sites subfolders for any sites hosted by your Drupal code. The absolute minimum is a settings.php file in a subfolder named something like /sites/example.com/.

3) There is no fourth step.

Why not just use site.php

rwilson0429's picture

The simplest method is to use Drupal 7's site.php to implement multi-sites using the same code base. The sites.php is stored in the sites directory, if you have installed Drupal 7 you should see a file called example.sites.php. Rename example.sites.php to sites.php, then uncomment and change the $sites array as needed.

* Multi-site directory aliasing:
* Edit the lines below to define directory aliases. Remove the leading hash
* signs to enable.
$sites['example1.com'] = 'example1.com';
$sites['example1.localhost'] = 'example1.com';

Multi-site install

tsssystems's picture

1) www/d6core in your earlier post is above the web root.
2) @rwilson0429 is right; in your latest example you haven't set up sites.php. "example.sites.php" will get you no where. Is settings.php also set up correctly? Are you sharing any tables between the multi-sites? Have you followed all the instructions there regarding the database setup? Perhaps you need to uncomment the base install directory line in settings.php. Is the cookie domain set correctly?
3) Did you actually run install.php for each sub-site you want to set up? Drupal needs to build the database and set up a few paths before the site will work. If you didn't run install.php from your subdirectory then you won't have a site set up in that subdirectory.

www/d6core wasn't me

mstrelan's picture

1) www/d6core wasn't me, that was the original post, I seem to have hijacked the thread.

2) I have tried with and without sites.php. The settings.php files are default after an installation. Have not modified cookie domain or base url.

3) No, I had just cloned the database and settings.php. But now I've cleared out the database and copied default.settings.php so I could run install.php, but it doesn't get that far because /example is still 404 page not found.

Perhaps could someone set up a working example that we can all see of how it's meant to work without symlinks, I'm curious if my server is the issue.

Another approach to installing Drupal 7 multisites

Lakeside's picture

This article demonstrates one way to install a multisite. The approach works on most virtual host servers.



Lakeside's picture

Why is it that Symlinks are not being used and the domains are all seen as separate sites?

Please demonstrate working example

mstrelan's picture

If you have subdirectories working as a separate website, sharing the same codebase, without symlinks, please show us a working example.


Lakeside's picture

You're skeptical that you don't need to use sym links to get a Drupal mulitisite to work?

I'm happy to prove it, but how are you going to detect that it really is a domain sitting in the site folder of Drupal installed in the root folder?

There is a procedure that you do need to follow to install the subdomain; otherwise you do need to use sym links for it to work. Here are the basic steps that work on Apache virtual host servers (the site was recently moved from a Drupal multisite to WordPress):


i posted below how my

Karll's picture

i posted below how my multisite is running, I am running 14 sub sites this way with no symlinks -

No symlinks used:
Each site has its own unique database:
Drupal is the root directory in apache:

Website sub directories under /var/www/drupal/sites/

sites/default - not writable

DNS:examples www.a.com www.b.com www.c.com www.d.com

For each new multisite I create - I copy the default directory and rename it to the URL -
"sudo cp -R defaultsetup -new folder name-"
then make writable to the webservice name
"sudo chown -R www-data.www-data /var/www/drupal/sites/-NEW-SITE-FOLDER-"

I am exiting this

mstrelan's picture

I am exiting this conversation. No one seems to be paying attention to the fact that I am not referring to sub.domai.ns, I am referring to sub.direct/ories/

Right. default.settings.php

Mile23's picture

Right. default.settings.php tells you how to do that. Something like:


It works the same way as the domain names. Drupal will find it. No symlinks needed.

From default.settings.php:

* For example, for a fictitious site installed at
* http://www.drupal.org/mysite/test/, the 'settings.php'
* is searched in the following directories:
* - sites/www.drupal.org.mysite.test
* - sites/drupal.org.mysite.test
* - sites/org.mysite.test
* - sites/www.drupal.org.mysite
* - sites/drupal.org.mysite
* - sites/org.mysite
* - sites/www.drupal.org
* - sites/drupal.org
* - sites/org
* - sites/default

@ mstrelan Above you asked

Karll's picture

@ mstrelan

Above you asked for a working example of using a single codebase using subdirectories working as separate websites - (a couple were provided) and several posts throughout this thread have indicated that you do not need to use symlinks for a multisite setup. (The original post was about infinite folder path recursion). I Think the common census here is that symlink is not needed and being over thought and theres not a straight clear answer in the documentation. Both subdomains as a separate website as well as unique website domain urls both function the same way if you want to use a multisite. It all depends on your level of access to DNS and the webserver.

in the Drupal installation under /sites/ folder you copy and rename the sites"default" to a new folder named what your URL will be.

all are folders:

or if you have only one domain but need multiple sites:


They all work the same. then in DNS you point all urls "domains" at the same ip address. For subdomains would be the same thing "all point to the same IP address.

Drupal handles the rest.!

I am no expert on symlinks -
I personally have never used them. I have always understood symlinks to be used as that you have one domain name pointed at a Drupal site but have registered all the ".com .org .net"
but when you visit "www.mysite.com" your Drupal site works. If you want to visit www.mysite.net or .org Drupal does not know where they are because the folder does not match. It was my understanding that you create symlinks to point www.mysite.org and www.mysite.net at the folder www.mysite.com.


gclicon's picture

@mstrelan I had to login and point out that I'm just as frustrated as you are reading through this post hoping to find an answer for a similar situation I'm in.

when drupal in the webroot

Karll's picture

when drupal in the webroot receives a request at the IP - it takes the url used and looks for a matching sites folder - when one is not found it rediects to 404

no symlinks multisite

Karll's picture

No symlinks used:
Each site has its own unique database:
Drupal is the root directory in apache:

Website sub directories under /var/www/drupal/sites/

sites/default - not writable

DNS:examples www.a.com www.b.com www.c.com www.d.com

For each new multisite I create - I copy the default directory and rename it to the URL -
"sudo cp -R defaultsetup -new folder name-"
then make writable to the webservice name
"sudo chown -R www-data.www-data /var/www/drupal/sites/-NEW-SITE-FOLDER-"

I can understand mstrelan

OriginalSauce's picture

I can understand mstrelan frustration as in my opinion his question was never really answered.

It is not always as easy at some posters make out. The people who say Drupal works straight out of the box I find never give very concise answers on how they managed it. The answers are about as useful as the documentation you often get, extremely cryptic and incomplete.

I've found with Drupal to get things to work as you want you often have to shoe horn something in here or customise something there.

A lot of the posts went on about sub domains rather than subdirectories. It is my believe as mstrelan posted

"Symlinks are needed for SUBDIRECTORIES as separate sites."

sites.php doesn't work on it's own. It doesn't automatically direct you to the website contained within the subdirectory. I have a site.php which is correctly set up.

It doesn't work out of the box as some posters have said it does. For it to work, you need to either use a symlink or introduce a rewrite or a virtual host alias.

I'm in the exact same situation as the OP. I have been using symlinks for my subdirectories as separate websites. Removing the symlink means I can no longer access my subdirectory websites. I know because when I first created the multisites I tested this. And now on removing it this minute.

These are not separate subdomains accounts created in cpanel or a separate registered domain name(s). They don't exist anywhere apart from their location in the subdirectory (with its associated DB).

A number of reasons I want to remove the symlink is having read this post, I do not want the recursive issues. I also believe it is interfering with apcu and various other caching methods that are now being set up on my dedicated server.

adriancotter's picture

Hey OriginalSauce, I can agree that things are not always so simple, however I can state categorically that symlinks are not needed for sub directories -- because we do it all the time.

Here's a few actual examples:

These are three separate site databases. The actual directory structure in /sites/ look like

ourwildamerica and evguide are also set up as virtual directories that point to the drupal folder. We use IIS, so I don't know how virtual directories are done in apache. But once you have that there is no other set up to get this to work (outside of the work of setting up any site -- having settings.php and a db ready).

One use case for symlinks where you have a Dev or test site would be so that you could keep the same directory structure, and use a symlink to point dev.sierraclub.org at content.sierraclub.org (I've also heard symlinks being used to maintain a codebase for Drupal core separate from the sites folder)

However, the sites.php file is a much better way to do manage different dev/prod domains (using symlinks caused no end of problems), because you can just have sites.php point dev.sierraclub.org at content.sierraclub.org

In fact, had a I known this much earlier, I would have used sites.php a lot more, and just named those directories more simply
and used sites.php to make sure that the multi site was going to handle them correctly, for example:
$sites['dev.sierraclub.org.ourwildamerica'] = 'ourwildamerica';
$sites['dev.sierraclub.org.evguide'] = 'evguide';

Thanks for your reply

OriginalSauce's picture

Thanks for your reply adriancotter.

It does give me some encouragement that it can be achieved, however, I still don't have any luck without using the symlinks in my case.

I have full access to the CentOS server and therefore all the config files etc which gives me all the necessary tools to make this work but am being frustrated.
I admit I'm no expert with rewrite rules etc but I can follow instructions very well and from all accounts it's a pretty straight forward procedure.

In my situation with following the procedures (simple steps of updating the vhost config file, apache restart etc), if I remove the symlinks the sites stop working.

I have a question for you.

You mention the sites.php (which I have configured but is redundant when using symlinks) which you would have used if you had known about it. Have you used this in a working environment without any of the above virtual directories? In other words have you seen it work as it should?

I've read the sites.php doesnt exactly work as it was intended. Well in the case of using subdirectories as sites at least.

Hey OriginalSauce, I have

adriancotter's picture

Hey OriginalSauce,

I have never set up a subdirectory site with a symlink so I am not sure how that would even work honestly.

sites.php works great for us (and so far as I know as intended) -- but is unrelated to the problem of getting a site in a subdirectory. you don't need sites.php for subdirectories to work either (I was just suggesting a possible convenience factor).

We have only ever set up sub directory sites using virtual directories. The virtual directory points at the root of drupal i.e. something like c:\wwwroot\drupal

The settings file, and files, themes, etc for the site then go in a folder that is named for the domain.directory

Another way to see this in action is to download something like Acquia DevDesktop -- you can set up sub directory sites using that (in settings>sites>new -- you add a "url path" in setting up a site). It does all the work for you. DevDesktop uses Apache -- not sure how different that would be from CentOS, but you could poke through all the hosts files and whatnot.

Thanks for the tips. It's

OriginalSauce's picture

Thanks for the tips. It's been awhile since I've run a local environment. What with speeds and internet access everywhere these days, all dev work goes straight on the server.

The way you've set up yours sounds exactly how I've set up mine in terms of directory structure etc. It might make sense to set up locally as it may reveal some answers.

Thanks for taking the time to reply.

Perhaps it's an issue with

mstrelan's picture

Perhaps it's an issue with the default configuration of Apache on CentOS/cPanel...

This could well be it,

OriginalSauce's picture

This could well be it, however, the setup doesn't veer too far from the base build and there are a goodly number of live websites using it. Then again all the other sites are single domain.

Like adriancotter suggested, using a local setup may shed some more light on the situation.

I would love to do away with the recursive issue.

Apache might be the culprit.

misterkay's picture

Apache might be the culprit. I'm having the same issue with Apache on Red Hat with no cPanel.

I had a lot of difficulty tracing back where the path resolution actually happens within D7 core.

Regardless of which of the two is the problem here, it comes down to the site following symlinks and not realizing it has ended up in the same place.

It's probably worth noting

misterkay's picture

It's probably worth noting that when it loads a /site1/site2 path that the following variables behave as such:

$_SERVER[script_name] = /site1/site2/index.php
$_SERVER[script_filename] = <drupal_root>/site1/site2/index.php
base_url = <site root>/site1
base_path = /site1/

In the case of any page that doesn't match the above /site1/site2 type those variables are:

$_SERVER[script_name] = /site1/index.php
$_SERVER[script_filename] = <drupal_root>/site1/index.php
base_url = <site root>/site1
base_path = /site1/

Perhaps the fault lies in how $_SERVER[script_*] variables are determined.

We are also facing the same

kyawzayl's picture

We are also facing the same issues with symlinks and sub-directory sites.

These we think is not good for the SEO and when we do the google search, these results are showing unexpectedly :(

Has anyone found out the solution yet? Thanks.

The solution is RTFM.

Mile23's picture

The solution is RTFM. :-)

Don't use symlinks.

If your goal is to simply have site1.com, site2.com, and site3.com, then that's the simplest use-case for multi-site.

Set up a fresh new Drupal site. Go through the install process.

Your web server's docroot should be the Drupal directory. (The one with index.php in it.) This is the most important step. Do not ignore this step. If your Drupal installation's front page URL looks like example.com/drupal, then you are doing it wrong.

All domains and subdomains to be hosted by this Drupal installation should use this same web server and the same docroot. This is utterly and completely important. :-)

Notice that you have a sites/default directory with a sites/default/settings.php file and a sites/default/files directory.

Make a copy of default/. Rename it something like example2.com. This leaves you with a sites/example2.com/ directory, with its own settings.php and files/.

You now have a multi-site installation and can go buy yourself lunch.

No symlinks needed.

No change to .htaccess needed.

Any request for example2.com will be magically understood by Drupal to read settings from sites/example2.com/settings.php.

You would likely change the new settings.php file to reflect another database or prefix setting, but mostly, you're done.

Repeat for other domain names.

I have to say, although, I'm

OriginalSauce's picture

I have to say, although, I'm sure you posted your reply to be helpful, I don't think it was that helpful in this case.

You are referring to sub domains, which the OP is not referring to. The set up is subdirectories as subsites. Therefore,

site1.com site2.com and site3.com are not good examples in this case.

This might be one good way to set up a multi-site, but again it's not what the OP is referring to.

I have RTFM and it actually advises symlinks as a solution. As it's in the manual I would assume it's a 'good' solution.

That all being said, disregarding the exact format you refer to (site1.com etc), my set up is pretty much as you describe.

Without the symlink, the subdirectory subsites I have break.

This is my setup and it's not going to change as it works very well for my purposes, apart from the recursion.

Thanks for the reply. Like

kyawzayl's picture

Thanks for the reply. Like you said, yes, the subdirectory sites break without the symlink pointing to those. Since we can't seem to solve this symlink issue yet, we have decided to use subdomains already to avoid this recursive urls issue. Please keep us posted if you have any solutions. THanks.

Thanks for your reply. In

kyawzayl's picture

Thanks for your reply. In fact we are running multisite with subdirectories and not subdomains. So our sites are like,

http://sites.com/site1 (sites/site1)
http://sites.com/site2 (sites/site2)

And we have structured it to use it with symlink instead of subdomains but we can't avoid the recursive issue if we use symlink. So we have decided to use subdomains already. Thanks anyway.

It works the same way.Follow

Mile23's picture

It works the same way.

Follow my directions above, and instead of changing the name of the sites subdirectory to example.com, change it to example.com.site2. That will cause Drupal to use those settings for a request to http://example.com/site2.

You can keep adding URL path elements to the name of your folder. You could have a sites/ subfolder named example.com.this.is.a.bit.ridiculous.but.it.still.works, and if a request comes for http://example.com/this/is/a/bit/ridiculous/but/it/still/works, Drupal will dutifully map it there.

Symlinks: bad.

Thank you for taking the time

misterkay's picture

Thank you for taking the time to reply, but again, you seem to be missing the point of this conversation.

Symlinks are not 'bad'. They are the recommended action as per the installation instructions (https://drupal.org/documentation/install/multi-site#symlink).

There is an unintended side-effect while using them that http://example.com/site2/site1 will point to site2's front page instead of a page in site2 with the alias 'site1' and http://example.com/site1/site2 will point to site1's front page instead of a page matching the alias 'site2' in site1.

Not using symlinks is not a possible solution in some cases.

I see now

adriancotter's picture

Misterkay, I see -- I'm on IIS so we use virtual directories to get sub-directories to work. From that documentation, it looks like symlinks are the equivalent for Apache.

So back to the original question... is there anyway around those unintended side effects of the nesting URLs?

etc, etc

I actually do have the same issue in IIS, although it will only go one layer deep.

Using .htaccess to provide 301 redirects for SEO

tommycox's picture

With the utmost empathy for those who have torn their hair out trying to figure out a workaround, and for future comers who may never know how frustrating debugging this can be, one can fix this using an n2 amount of .htaccess redirects like so:

RedirectMatch 301 /site1/site1/(.*) http://<your_site>.com/site1/$1
RedirectMatch 301 /site1/site2/(.*) http://<your_site>.com/site1/$1
RedirectMatch 301 /site1/site3/(.*) http://<your_site>.com/site1/$1

RedirectMatch 301 /site2/site1/(.*) http://<your_site>.com/site2/$1
RedirectMatch 301 /site2/site2/(.*) http://<your_site>.com/site2/$1
RedirectMatch 301 /site2/site3/(.*) http://<your_site>.com/site2/$1

RedirectMatch 301 /site3/site1/(.*) http://<your_site>.com/site3/$1
RedirectMatch 301 /site3/site2/(.*) http://<your_site>.com/site3/$1
RedirectMatch 301 /site3/site3/(.*) http://<your_site>.com/site3/$1

This should cover any scenario of paths strung together and will redirect to the appropriate page i.e. http://site.com/site1/site1/site2/site3/site1/technology/software will 301 redirect to http://site.com/site1/technology/software.


Hi Tommy, Bit of a late

OriginalSauce's picture

Hi Tommy,

Bit of a late reply, but thanks for such a neat solution/work around. It's now part of my setup.


Nice! Worth Testing

rCharles's picture

Thank you Tommy. Worth testing.

Nice! Worth Testing

rCharles's picture

Thank you Tommy. Worth testing.

Nice! Worth Testing

rCharles's picture

Thank you Tommy. Worth testing.

hansfn's picture

I prefer 1 amount of redirects ;-)

RedirectMatch 301 /(site1|site2|site3)/(site1|site2|site3)/(.*) http://example.org/$1/$3

PS! This thread was about Drupal 6, but this is relevant for Drupal 7 and 8 too.

Very crafty! Thanks for

tommycox's picture

Very crafty! Thanks for updating the documentation as well :)

Multisite sites folder

jukka792's picture


I have multisite setup where everything is working fine. Only thing is that I can't make "images" folder under each multisite and find the images there simply putting "multisite1/images/"

My setting is:
www.rootsite.com (htdocs/sites/default/settings.php)
And under that many multisites:
www.site1.com = (htdocs/sites/site1.com/settings.php)
www.site2.com = (htdocs/sites/site2.com/settings.php)

Also I have "files" folder under each;

Problem is that how to make for example "images" folder under each site? When I created:
htdocs/sites/site1.com/images -folder
I can't access it using "www.site1.com/images" because it shows the content of www.rootsite.com/images.

Should I use symlink and how, or what could be the best solution here?

For example URL "www.site1.com/images/picture.png" tries now to find the file from "www.rootsite.com/images/picture.png" -location but I want it get the file from "htdocs/sites/site1.com/images/picture.png"

It's been a while since I've

tsssystems's picture

It's been a while since I've used multi-site (was using it for dev purposes), but as I recall you need to put your images folder in the files folder, e.g., htdocs/sites/site1.com/files/images, htdocs/sites/site2.com/files/images . You can also make other directories for other file types - I had a separate directory for PDF files, for example. Remember your "site1.com" and "site2.com" etc directories are taking the place of the "default" directory in the root installation.

mamatawal's picture

If sites.php is set up correctly based on what drupal suggesting for Multi-site sub-folder, what you need to see further actually is vhost config in your httpd

just add alias for your document root like example below:

<VirtualHost *:80>
    DocumentRoot "var/www/drupal"
    ServerName www.example.com
    Alias /site1 "var/www/drupal"
    Alias /site2 "var/www/drupal"

Then, drupal will handle everything for you when it know what your document root is :)

Do you have a working example

misterkay's picture

Do you have a working example of this? Does this allow you to have the following URLs working?



Multisite Documentation for Subdirectories

brenk28's picture

Just wanted to point to the documentation here: https://www.drupal.org/docs/7/multisite-drupal/multi-site-in-subdirectories as I didn't see it in the thread and it provides the answer to the origin question, how to prevent infinite recursion with a multisite setup using a subdirectory.

Drush and Drupal Mulsite for Subdirectories

humansky's picture

How fortuitous, just last night I ran into this same situation, but with drush and infinite redirects. Here's my solution, in case anyone was wondering: