4

I have Drupal installed in a subdirectory of public_html on BlueHost.

It looks like this: /www/drupal7/mywebsite.

I want to run the site out of the mywebsite subdirectory instead of www. However, I want the URL to appear to be http://mywebsite.com.

Here is the suggested .htaccess configuration from BlueHost. This is the .htaccess for the www/ directory; I am using the default Drupal 7 .htaccess in Drupal's subdirectory.

# BlueHost.com 
# .htaccess main domain to subdirectory redirect 
# Do not change this line. 
RewriteEngine on 
# Change example.com to be your main domain. 
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 
# Change 'subdirectory' to be the directory you will use for your main domain. 
RewriteCond %{REQUEST_URI} !^/subdirectory/ 
# Don't change the following two lines. 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
# Change 'subdirectory' to be the directory you will use for your main domain. 
RewriteRule ^(.*)$ /subdirectory/$1 
# Change example.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.)?example.com$ 
RewriteRule ^(/)?$ subdirectory/index.html [L]

This successfully allows me to use Drupal from the subdirectory, but the URLs look like this:

http://www.mywebsite.com/drupal7/mywebsite/PAGE

But I want it to look like this:

http://www.mywebsite.com/PAGE

This post on Drupal.org suggests that the $base_url must be set in default/settings.php. I set the $base_url to "http://mywebsite.com"; however, when I do this, whatever link I click, I am redirected to the front page.

Is there an additional step? What am I missing?

8
  • you need to include the directory name in base url like "mywebsite.com/mywebsite"
    – Bala
    Jan 12, 2014 at 5:30
  • 1
    @Bala When I include the directory name in the base URL, then the directory name shows up in the URL. How can I serve the pages properly without showing the directory name in the URL? Jan 13, 2014 at 1:51
  • @PatrickKenny why dont you use the default Drupal .htaccess file ?
    – niksmac
    Jan 15, 2014 at 4:54
  • @PatrickKenny Do you have access to change the apache web server configuration files on your bluehost account? Jan 15, 2014 at 5:25
  • 1
    The problem with the redirection to your homepage could be linked to Clean URLs. I would suggest to disable it first, configure your website, and enable again.
    – Matt
    Jan 15, 2014 at 16:20

3 Answers 3

2
+50

It sounds like the answer from Oleg Ivanov would work. However, if you want to tackle this with a .htaccess approach, the following works for me. Find and replace SUBDIRECTORY with your subdirectory.

Amend your Drupal's .htaccess with the following:

RewriteBase /

# homepage redirect
RewriteRule ^$ /SUBDIRECTORY/index.php?q= [L]

# if directory or regular file...
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_URI} =/favicon.ico
# stop here
RewriteRule ^ - [L]

# if a regular file in SUBDIRECTORY directory
RewriteCond %{DOCUMENT_ROOT}/SUBDIRECTORY/%{REQUEST_URI} -f
RewriteRule .* SUBDIRECTORY/$0 [L]

# Redirect everything to /SUBDIRECTORY
RewriteRule .* /SUBDIRECTORY/index.php?q=$0 [QSA]
1

Use the default .htaccess shipped with drupal and

  1. Make sure line 110 is commented like this

    # RewriteBase /

  2. Uncomment and edit line 106 to read like this

    RewriteBase /drupal7/mywebsite

4
  • I tried this but I'm still having the same problem-- whatever link I click, the URL changes but the front page content is displayed. Jan 15, 2014 at 10:53
  • @PatrickKenny can you just remove the base_url form your settings.php and try ?
    – niksmac
    Jan 15, 2014 at 11:37
  • When I remove the base_url, then the pages are loaded properly, but the URLs look like this: http://www.mywebsite.com/drupal7/mywebsite/PAGE Jan 15, 2014 at 12:45
  • I think some rewrite rule will work try this RewriteRule ^drupal7/mywebsite/(.*)$ index.php$1 [R,L] use this in line 117 of drupal htaccess
    – niksmac
    Jan 15, 2014 at 14:39
1

I host several of my Drupal websites on BlueHost, and I've achieved basically what you're asking without changing any of .htaccess files:

here's what I do - (I have a separate Drupal installation for each site for a number of reasons, although I believe the same can be done with a multi-site install)

I have a Drupal installation in /public_html/mywebsite;

I add http://mywebsite.com to my account via "Assign Domain", as an Addon Domain -

in Step 4 - "Choose Addon Directory and Sub-domain" - I choose "Use an existing directory" (from a list of sub-directories under public_html) - mywebsite; (it also appears as mywebsite.mymainaccountdomain.com - so be it, I just don't use it)

after all the changes propagate through BlueHost servers' "insides" (sometimes takes up to 15 minutes, especually for 'www' redirect to catch on) -

my site is accessible as both http://mywebsite.com and http://www.mywebsite.com and all its pages load as expected - http://www.mywebsite.com/page and so on

hope this helps

3
  • 1
    This is a straightforward approach, except apparently it doesn't work if you are trying to re-assign the first domain registered with the account (the primary domain). I talked with Bluehost support, but apparently the first domain cannot be redirected from the UI. Jan 19, 2014 at 3:45
  • unfortunately - yes, it seems that nothing can be done through their UI for the primary domain Jan 20, 2014 at 19:12
  • @Patrick - did jwal's suggestion work for you? I tried that approach for my 'primary' domain - used the BlueHost's .htaccess from the initial post for /public_html folder and jwal's one for my /public_html/mywebsite folder - but I'm getting the same URL that you were getting at the beginning - http://www.mywebsite.com/mywebsite/PAGE is there anything I'm missing? Jan 21, 2014 at 23:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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