Taking your site live

Last modified: November 9, 2009 - 09:05

Once you've got your Drupal installation set up just the way you want it, there are a few final considerations before you unleash it on the world.

Moving from a temporary location

It's likely that you've put Drupal in a subfolder on your server, so it doesn't interfere with your existing website while you get it set up. So you have www.example.com showing your old site, www.example.com/drupal showing drupal, and you want www.example.com to show off your new site to the world. There are two ways you can go about this:

Moving Drupal

For newer versions of Drupal, moving the Drupal base folder shouldn't pose any problems. For versions prior to Drupal 5, some settings may need to be changed so Drupal can find everything. See this forum thread for more details.

Redirecting your server

Alternatively, you can leave Drupal where it is in a subfolder, and just have your webserver fool everyone into thinking that folder is www.example.com.

With Apache, you need to add the following to the .htaccess in the root folder (or create an .htaccess file if there isn't one there):

RewriteEngine on
#
# stuff to let through (ignore)
#RewriteCond %{REQUEST_URI} "/folder1/" [OR]
#RewriteCond %{REQUEST_URI} "/folder2/"
RewriteRule (.*) drupal/$1 [L]

Use the RewriteCond rules to let through URLS without modification (for example, you might have other subfolders you still want accessible). Replace 'drupal' with the name of the folder Drupal is in.

You also need to modify the settings.php file for your site. By default, this is at sites/default/settings.php. Uncomment (or change) the line that sets $base_url, and set it to the URL you want browsers to see as the base for your site:

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

In other words, ensure that this does not include the drupal subdirectory. This changes the links that Drupal generates so they point to the correct location.

Excluding paths from Drupal

It may be that your site is made up components other than Drupal, or that you have an archive version of your old site you want to be browsable. Drupal in a root folder takes over all URLs; Drupal in a subfolder fooled into thinking it's root likewise.

Either way, the .htaccess file in the root folder needs to be changed to let through the paths to files or folders you want Drupal to ignore.

In the case where Drupal is in the root folder, here's what you need to do:

  1. In the your webserver root's .htaccess file, find the section marked with the comment '# Various rewrite rules.'
  2. Below 'RewriteEngine on' but before any other rules, add lines in the following form:
      RewriteRule /folder - [L]     # a subfolder Drupal should ignore
      RewriteRule /file.html - [L] # a file in root Drupal should ignore

This page is a work in progress. Please suggest other tasks it should cover.

Hiding the subdirectory...

CheckeredFlag - April 12, 2007 - 19:31

The trick to hiding the drupal subdirectory is not letting drupal know about it - only the rewrite rule.

Put this rewrite rule in .htaccess:

RewriteRule ^/(.*) /drupal/$1 [L]

However, ensure that the $base_url variable in settings.php does not include the drupal subdirectory:

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

This will convert a request for:
http://www.example.com/index.php
to
http://www.example.com/drupal/index.php

Drupal will then generate URLs without the subdirectory and depend on the rewrite rule to fix it.

(Note that I've only tried this with drupal 5.1 on IIS)

BTW, note that your rewrite rule is slightly incorrect in that a request for /index.php would be translated into drupal//index.php, which might be harmless but incorrect nevertheless.

I really want to do this!

solutionsphp - August 28, 2007 - 19:30

More on hiding the subdirectory

jkahn117 - October 19, 2007 - 17:07

The tip from mmoreno does work on Apache as well, with some minor modification (tested on Ubuntu 7 + Apache 2.2.4).

Within my virtual host configuration (I have Drupal running with HTTPS access only), I added the following:

RewriteRule ^$ /drupal/ [L]
RewriteRule /phpmyadmin - [L]
RewriteRule ^(.*) /drupal/$1 [L]

Originally, I only had the last two lines above, however, this caused a "Bad Request" error in Apache because of a bad URI. After some digging, I decided to add a special rule to handle requests to "http://www.example.com" as well. This corrected the Bad Request issue and now my Drupal installation is running perfectly.

subfolder .htaccess with exemptions uncommented failed for me

bks - July 22, 2007 - 19:38

i had to do something more like:

RewriteEngine on
#
# stuff to let through (ignore)
RewriteCond %{REQUEST_URI} "!/folder1/"
RewriteCond %{REQUEST_URI} "!/folder2/"
RewriteRule (.*) drupal/$1 [L]

(invert conditions and use implicit AND)

brian

A solution for godaddy hosted sites

bsenftner - July 16, 2009 - 19:14

I've documented how to get drupal in a subdirectory with godaddy hosting here:
http://drupal.org/node/520700

 
 

Drupal is a registered trademark of Dries Buytaert.