My main site, www.mysite.com, lives in /public_html/drupal/
The test site, sandbox.mysite.com, lives in /public_html/sandbox/drupal/
I used some code I found on drupal.org to configure the htaccess as to hide the drupal folder:
Options -Indexes
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]
RewriteRule .* http://www.mysite.com/ [L,R=301]
RewriteRule ^$ drupal/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/drupal%{REQUEST_URI} -f
RewriteRule .* drupal/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* drupal/index.php?q=$0 [QSA]
So now sandbox.mysite.com resolves to www.mysite.com. I really need the sandbox site to work. Would someone be so kind as to show me how configure the htaccess to do that?
Comments
You only need to do what
You only need to do what you're asking if you don't want to (or can't) put your drupal site in root. I only use this method because I am forced to not use root - I share our web space with other departments, and we agreed that no one particular script should physically be in root. Although because I develop the main website, we agreed that I could use the main domain for it rather than a subdomain. So I can tell you the way I am working at the moment, but I can't guarantee that it won't cause you problems.
When Drupal site can't go in root:
====================
My dev site is in a proper subdomain: dev.domain.net
My main site is also in a proper subdomain: web.domain.net
As long as all internal links are 'partial absolutes' starting with /sites
(ie. /sites/default/files/image.jpg)
... then the website is easily transferable between the 'dev' and 'web' folders.
Now then, I don't want the main site to appear as though it is in a
subdomain, so I used a variation of the htaccess script you posted:
First I globally redirect www to http://
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Then redirect *only* http://domain.net to http://domain.net/web
RewriteCond %{HTTP_HOST} ^DOMAIN\.NET$ [NC]
RewriteRule ^$ WEB/index.php [L]
Then hide the 'web' folder in the url:
RewriteCond %{HTTP_HOST} ^DOMAIN\.NET$ [NC]
RewriteCond %{DOCUMENT_ROOT}/WEB%{REQUEST_URI} -f
RewriteRule .* WEB/$0 [L]
RewriteCond %{HTTP_HOST} ^DOMAIN\.NET$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* WEB/index.php?q=$0 [QSA]
And in the /web/sites/defaults/setting.php, edit: $base_url = 'http://domain.net'
So I access my main site with: http://domain.net which is 'redirected' by the
1st & 2nd lines of the script to http://domain.net/web, but then the url is rewritten
back to http://domain.net and everyone is very happy.
I access the dev site with: http://dev.domain.net
Other department using other scripts put them in subdomains and access them with:
http://script.domain.net and I haven't had any problems or complaints so far. And
in fact, I tested all this quickly with a subdomain 'multi-site' and couldn't see any
problems.
However, if you *can* put your drupal site in root, then you are far better to do it.
Drupal site in root:
===========
Dev site goes in a subdomain: http://dev.domain.net
Main site is in root: http://domain.net
As long as the internal links are partial absolutes starting with /sites you
can easily move your site from root to dev and vice versa, without the need or
dangers of using the above htaccess script.
Hope that helps.
That info represents about two weeks of research, blood and tears ;)
The easy and clean way is to
The easy and clean way is to set up a subdomain http://sandbox.example.com and map it straight to the /public_html/sandbox/drupal directory,
- either using a vhost if you have access to apache's httpd.conf,
- or from your cpanel if it gives you the option to map a subdomain wherever you want
- or from your cpanel, and additionally a symlink to the destination.
If the sandbox and the main site are different drupal installation, that should be enough. If they are both running from the same Drupal installation then you will need to do the additional steps required for a Drupal multisite (mapping all the sites to Drupal's directory, and setting up drupal/sites/site-name subdirectories to hold each site's settings).
Exhaust all other options first. The .htaccess methods are a last resort.
I figured it out.
I was trying to make it to complicated. Instead of one htaccess, I needed two. One controls the main site as usual. The second goes into the sandbox root dir. Everything works fine now.
jdcllns