Multiple domains, one code base

Using a single web hosting account to host multiple sites

Multiple domains, one code base

Postby Maelstrom » Fri Jan 23, 2009 4:25 am

I am making a CMS type application that will host multiple sites. For ease of maintaining it all, they will all run off the one code base, on the one server. So far, I have it mostly working, except one small detail. The setup:

Code: Select all
httpdocs/
   cake/ - A folder holding CakePHP (http://cakephp.org/)
   sites/
      domain1.com/
      domain2.com/
      etc...


The plan is to have all CSS/Images/templates/etc that are unique to each site in the sites respective folder. When someone accesses, say, 'http://domain1.com/foo/bar.jpg', it should check 'httpdocs/sites/domain1.com/foo/bar.jpg'. If this exists, serve this file. If it doesnt exist, redirect to the cake/ folder. Cakes own mod_rewrite will handle things from there.

I have the following .htaccess file in the httpdocs folder:
Code: Select all
<IfModule mod_rewrite.c>
   RewriteEngine on
   
   RewriteCond "/www/cms/httpdocs/sites/%{SERVER_NAME}/$1" -d [OR]
   RewriteCond "/www/cms/httpdocs/sites/%{SERVER_NAME}/$1" -f
   RewriteRule ^(.*)$ /sites/%{SERVER_NAME}/$1 [L]
   
   RewriteRule    (.*) cake/$1 [L]
</IfModule>


This all works fine, except that accessing, say, 'http://domain1.com/sites/' will bring up the FancyIndex listing of the directory contents. In this case it is obviously a list of all the sites being hosted by this CMS. This happens for all folders in /httpdocs.

Also, when I access 'http://domain1.com/foo/', and the folder '/foo/' exists, the FancyIndex header shows 'Index of /sites/domain1.com/foo', where as I would much prefer for security reasons as well as cosmetic reasons for it to show 'Index of /foo'.

I could just turn off FancyIndexing, but this still allows people to access the material of other sites where they are not supposed to. This is not really a solution.

My questions are:
1) How to stop people accessting /sites and other folders in /httpdocs. Requests to these should be sent through to /sites/SERVER_NAME/sites with everything else.
2) Fix the fancy index listing to display the 'correct' path, instead of the real path as it is now.

The second question might be solved with FancyIndex options, but as it is mod_rewrite playing havok initially, Im hoping this is the right place to ask.

Thanks
Maelstrom
 
Posts: 2
Joined: Fri Jan 23, 2009 3:39 am

Postby richardk » Fri Jan 23, 2009 11:14 am

Cakes own mod_rewrite will handle things from there.

What is that mod_rewrite like?

This all works fine, except that accessing, say, 'http://domain1.com/sites/' will bring up the FancyIndex listing of the directory contents. In this case it is obviously a list of all the sites being hosted by this CMS. This happens for all folders in /httpdocs.

...

1) How to stop people accessting /sites and other folders in /httpdocs. Requests to these should be sent through to /sites/SERVER_NAME/sites with everything else.

From the mod_rewrite posted if /sites/example.com/sites exists that should happen. Or if it doesn't it should get sent to /cake.
Code: Select all
<IfModule mod_rewrite.c>
   RewriteEngine On
   
   RewriteCond /www/cms/httpdocs/sites/%{SERVER_NAME}/$1 -f [OR]
   RewriteCond /www/cms/httpdocs/sites/%{SERVER_NAME}/$1 -d
   RewriteRule ^(.*)$ /sites/%{SERVER_NAME}/$1 [L]
   
   RewriteRule ^(.*)$ /cake/$1 [L]
</IfModule>


Also, when I access 'http://domain1.com/foo/', and the folder '/foo/' exists, the FancyIndex header shows 'Index of /sites/domain1.com/foo', where as I would much prefer for security reasons as well as cosmetic reasons for it to show 'Index of /foo'.

Mod_rewrite cannot control that.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Maelstrom » Fri Jan 23, 2009 8:18 pm

richardk wrote:
Cakes own mod_rewrite will handle things from there.

What is that mod_rewrite like?

Cake mod_rewrite redirects everything to /cake/app/webroot. Anything in here is served, otherwise it is handled by index.php in the webroot folder.
richardk wrote:
This all works fine, except that accessing, say, 'http://domain1.com/sites/' will bring up the FancyIndex listing of the directory contents. In this case it is obviously a list of all the sites being hosted by this CMS. This happens for all folders in /httpdocs.

...

1) How to stop people accessting /sites and other folders in /httpdocs. Requests to these should be sent through to /sites/SERVER_NAME/sites with everything else.


From the mod_rewrite posted if /sites/example.com/sites exists that should happen. Or if it doesn't it should get sent to /cake.


Sorry, I must not have been clear enough. Examine the following screen shots:
Image
This was from accessing http://nh.c.localhost/sites/. As you can see, there is no sites folder in nh.c.localhost. It is serving the listing for the sites folder containing all of the sites. This, beyond being wrong, is actually a security risk. You can even browse the directories for the other sites from a completely different site.

richardk wrote:
Code: Select all
<IfModule mod_rewrite.c>
   RewriteEngine On
   
   RewriteCond /www/cms/httpdocs/sites/%{SERVER_NAME}/$1 -f [OR]
   RewriteCond /www/cms/httpdocs/sites/%{SERVER_NAME}/$1 -d
   RewriteRule ^(.*)$ /sites/%{SERVER_NAME}/$1 [L]
   
   RewriteRule ^(.*)$ /cake/$1 [L]
</IfModule>


Also, when I access 'http://domain1.com/foo/', and the folder '/foo/' exists, the FancyIndex header shows 'Index of /sites/domain1.com/foo', where as I would much prefer for security reasons as well as cosmetic reasons for it to show 'Index of /foo'.

Mod_rewrite cannot control that.

I shall look around in FancyIndex options then to see if there is a solution.

Thanks for the reply.
Maelstrom
 
Posts: 2
Joined: Fri Jan 23, 2009 3:39 am

Postby richardk » Sat Jan 24, 2009 10:43 am

Cake mod_rewrite redirects everything to /cake/app/webroot. Anything in here is served, otherwise it is handled by index.php in the webroot folder.

Could you post it.

Sorry, I must not have been clear enough. Examine the following screen shots:
Image
This was from accessing http://nh.c.localhost/sites/. As you can see, there is no sites folder in nh.c.localhost. It is serving the listing for the sites folder containing all of the sites. This, beyond being wrong, is actually a security risk. You can even browse the directories for the other sites from a completely different site.

What i meant was that it should work like you want (example.com/sites to /sites/exmple.com/sites or /cake depending if /sites/exmple.com/sites exists or not) as far as i can see, so the problem is unlikely to be with that piece of mod_rewrite.

I shall look around in FancyIndex options then to see if there is a solution.

You could turn off indexes completely and use a custom directory index script
Code: Select all
Options -Indexes
DirectoryIndex index.php index.html /directoryindexer.php

And then any directory without an index.php or index.html file will get sent to /directoryindexer.php.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 22 guests

cron