Last updated 14 March 2010. Created on 14 March 2010.
Edited by remedios. Log in to edit this page.

When you're on a shared host like Lunarpages, you'll sometimes need to install drupal in subfolder. Often, you'll want to make it look like the subfolder is the base URL. To do that, edit .htaccess in your domain's public HTML root to redirect requests for pages, as instructed here:

You'll need to make sure that the redirect-to-subfolder command in your domain's .htaccess file isn't redundant with the settings.php (in sites/default/) $base_url line. If they're redundant, you'll get an infinite loop during certain tasks.

In sites/default/settings.php, you will have: $base_url = ''; // NO trailing slash!

DON'T list the base URL as$base_url = '';

To prevent an infinite redirect loop with sophisticated external connection applications and other errors, let the .htaccess file in the public HTML root (one folder above the subfolder) do the redirecting. Don't include your subfolder in your settings.php Base URL. This may seem obvious, but it is easy to miss because the redundancy doesn't cause problems until you use sophisticated programs like the fb modules.

Looking for support? Visit the forums, or join #drupal-support in IRC.


Neil’s picture

My site is located off of the web server root in a subfolder called foo. Before following the instructions in this article my site would appear as After it would appear as, which is what is wanted, but when clicking on the login menu item I get :

Index of /user

Name Last modified Size Description
Parent Directory

Basically a directory listing with no files in it. I have checked file ownership/protection and everything appears correct, at least to me.

I am new to Drupal so any help would be appreciated.

Runs on:

with Php 5.1.6


LupineDream’s picture

These worked for me, including themes, which would not load before, on a symlinked container outside public_html w/ a cpanel subdomain in bluehost:

ensure /sites/default/settings.php points at the full pathname of your subfolder.
ensure apache is confiugred (post vhost conf ) with:

# SPLENDID PUBFILE IDEBUGGED BY:  Bitnami Drupal Stack / WHM - LupineDream
<Directory "./public_hhtml">
    Options -Indexes +FollowSymLinks +ExecCGI
    AllowOverride All
    Require all granted
# SPLENDID FILTER MODULE IDEBUGGED BY:  Bitnami Drupal Stack / WHM - LupineDream
AcceptFilter http none
AcceptFilter https none
<IfModule mod_deflate.c>
          AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
          AddOutputFilterByType DEFLATE application/x-javascript application/javascript application/ecmascript
          AddOutputFilterByType DEFLATE application/rss+xml

Ensure mod_rewrite is enabled in php.ini
LoadModule rewrite_module modules/

login ssh as root
cd to your drupal container and then:

cd ..
chmod o+x ./drupal/sites/default/files        <- or wherever configured

symlink your outside-root container to your drupal installation:

cd /home/youruser
ln -s /your-drupal-path/ site

Use these instead of lunarsite for cpanel after you go add your subdomain (with a docroot of public_html/site)

# working for drupal by redirection to the symlinked container.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(main.)?$
RewriteCond %{REQUEST_URI} !^/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$$1

Should work now. What this does is symlink your container to public_html/site, which inherits all permissions configured for public_html and Options +FollowSymlinks allows the webserver to forward the content from the URL cpanel links to your subdomain to this symlink directly. Additional .htaccess block rules in post vhost httpd.conf allow the symlinks and cgi execution, and block nobody (your visitors) from chaning anything or figuring out you've symlinked.

Works and themes now work with the mod_rewrite condition on a subdomain for me. (tested).

Doing my container outside public_html lets me use composer to lock my dependencies too securly (nice!).

shane2peru’s picture

Ok, I setup drupal in a subfolder we will call drupal inside of public_html folder. I then created a and pointed it to public_html/drupal
Everything was fine, but I setup the sub.domain through cpanel, and made the document root to be drupal. I built my web site to my liking.

Now I follow these instructions to configure my primary site to be pointed to public_html/drupal following this guide with the lunarpages info, and the redirect works, however my site has no theme! All links seem to work, just no menu's, no blocks, no color, nothing, just words and links.

If I create a redirect with the cpanel it all works fine, except, when I go to the primary domain it looks just like that in the link. AS soon as i click a link, I get the <-- trailing folder name included in the url and it doesn't go away.

As specified in this guide I set the settings.php file to have the base URL as it should, without the folder. Any ideas would be greatly appreciated as I have played with this for several hours trying to get something set correctly. I commented out all the Rewrite stuff so my static site is still functioning for the time being, however this is quite annoying for me.


jonahruh’s picture

Hi Thanks for this post, I followed directions above and checked my settings.php file. My index page shows without the drupal folder, /d6, but when I click on any subpage menu, /d6 is still part of the url. For example If if i go up and delete /d6 from the url, the page will still display correctly and the /d6 won't get automatically reinserted into the url. But when i click on a menu item directly the /d6 is there. Do i need to rewrite more than just /index.php?

jonahruh’s picture

Uncomment and put site's domain in baseurl line in settings.php

smerny’s picture

I have a similar but totally opposite issue. I have a directory within Drupal that I don't want Drupal to touch. I am trying to do auto indexing (file directory pages) on this directory and all subdirectories... I've tried Options +Indexes and turning off RewriteEngine but nothing seems to work.

I have a sites/default/files directory, if I try going directly to this directory I get my Drupal headers with a message that says it couldn't find this page (instead of displaying a file listing for this directory). However if I go to something like sites/default/files/someFile.html, it will work as I expect (only showing the files content, no drupal headers). I posted my question here as well: