4

I am having issues with routing users to different domains on a shared hosting account. Each of these domains are separate Drupal installations with separate databases. site is intended to be the production environment, and site1-test is where we do our development and testing of content and modules prior to upload to the main site. Also, if it has any impact on this issue, clean_urls are enabled.

Here is my file structure

+ public_html
   + site1
   + site1-test

site1 should route to www.site1.com (or site1.com) site1-test should route to www.site1.com/site1-test (or site1.com/site1-test)

To me, this should be fairly straightforward updating of the .htaccess files.

Here is what I have done so far:

public_html/.htaccess

Options +FollowSymLinks
RewriteEngine on
#========================================================================
# FIRST Handle the http requests first before removing the additional url junk
#========================================================================
#rule for site1.com to link to site1 directory
RewriteCond %{HTTP_HOST} ^(www.)?site1.com$
RewriteCond %{REQUEST_URI} !^/site1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /site1/$1
#rule for site1.com/site1-test to link to site1-test directory
RewriteCond %{HTTP_HOST} ^(www.)?site1.com/site1-test$
RewriteCond %{REQUEST_URI} !^/site1-test/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ /site1-test/$1
#rule for site1.com to link to site1folder directory

#==========================================================
# SECOND Remove the additional url junk once the new url is loaded
#==========================================================
#rule for site1 url rewrite to remove /site1/index.php from the URL
RewriteCond %{HTTP_HOST} ^(www.)?site1.com$
RewriteRule ^(/)?$ site1/index.php
#rule for site1-test url rewrite to remove /site1-test/index.php from the URL
RewriteCond %{HTTP_HOST} ^(www.)?site1-test$
RewriteRule ^(/)?$ site1-test/index.php

public_html/site1/.htaccess and public_html/site1-test/.htaccess

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

  # no changes within <IfModule mod_headers.c> ...

public_html/site1/sites/default/settings.php

...
$base_url = 'http://www.site1.com';
...

public_html/site1-test/sites/default/settings.php

...
$base_url = 'http://www.site1.com/site1-test';
...

public_html/site1-test/sites/default/settings.php

So, there are multiple issues that I have. With the code listed above, all themes and login information is completely broken when visiting www.site1.com. However, visiting www.site1.com/site1-test works fine, although there are some issues with the Testing module (cannot run tests from the web interface, though I think this issue is linked to something being wrong in my htaccess file).

If I comment out the base_url for site1.com (i.e., //$base_url = 'http://www.site1.com';) then site1.com works, however all links show up as http://www.site1.com/site1, and all navigation after leaving the front page also shows that subdirectory.

Unfortunately I don't have access to the domain registration, but I do not believe that any redirects currently exist there, simply that the domain points to the site1 subdirectory.

0

Most shared hosting plans have a feature called subdomains or addon domains (these features exists in cpanel plans for sure. I m attaching a screenshot from a godaddy hosting plan). You may use this feature to effectively create a new apache virtual host so you dont have to mess with the .htaccess file to do the routing depending on the domain name

Also note that most shared hosting providers do not support overriding many features using the .htaccess file so many on of the options in your .htaccess file may be ignored depending on the apache configuration file (which you usually do not control)

Also note that .htaccess is an Apache concept. If your hosting provider uses another http server (e.g. nginx or IIS) the .htaccess file will be totaly ignored.

Last if you really want to do this with .htaccess (i dont recomend this) make sure you dont miss the query option in any of your cases. Notice the last part here index.php?q=$1 the ?q=$1 part is very important

search for those features or equivelant ones on your hosting admin tool

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.