Last updated December 21, 2012. Created on April 10, 2007.
Edited by neerajskydiver, jhomme, joachim, LeeHunter. Log in to edit this page.

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 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.

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

Comments

CheckeredFlag’s picture

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.

jkahn117’s picture

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.

bks’s picture

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

bsenftner’s picture

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

San_ANDREYEV’s picture

There is a database table for information about files attached to nodes named 'files'. It has a field 'filepath', which includes site name like 'sites/site_name/files/file_name'. I'm deploying drupal version of one of my sites near its current working version which is outside of drupal. Both are available as apache virtual hosts, so I'm unable to use site original name while deploying. Any ideas?

San_ANDREYEV’s picture

I used another port for new version of a site virtual host and renamed its directory inside drupal tree to real site name and that seems working - now I can work with something like real_site_name.domain:PortNum/node/nn and database stores correct pathes.

joachim’s picture

You can use symbolic links in the sites folder. The thing to do from start is to have your eventual live site folder name as the real folder, and the symlink be the site name your local site needs.

Seguinbg’s picture

sorry just starting with drupal
Would be good to add some words about steps for deploying to a " go live" server from a development machine
Thx

Wseguin

CarllosUK’s picture

Any luck with this?

I've been trying to take my website live for a while now but just can't work it out.

What's the process? How do you get all your modules, the database, and the theme files over to the live sever?

Thank you.

malcolm’s picture

"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)" - can someone clarify what the root folder is? Is that the folder where index.php, and subfolders, includes, misc, sites, modules, themes, etc. is? Thanks.

jestillore’s picture

let's say, you are using XAMPP,
you can place your files in C:\xampp\htdocs\drupal and it is accessible thru http://localhost/drupal
you root directory is the htdocs folder...

DrupalMan’s picture

Hello there.

I'm using drupal 6 on a cpanel based server and moving the installation folder from subdomain 'http://www.mydomain.com/web2' to another subdomain named 'http://www.mydomain.com/web' doesn't work. The site's homepage loads ok, but as soon as I try to load another page in it or logg in I get the message "Page not foud". It looks like the url's drupal created point to the old place.

I tried changing the file settings.php, uncommenting the statement and making it: $base_url = 'http://www.mydomain.com/web';

So moving drupal installation doesn't work on drupal 6? Do I have to use one of those strategies with .htaccess to be able to fool it into moving it arround?

Thx
DrupalMan

jestillore’s picture

i followed the instructions provided above...
it works fine when I accessed http://example.com
but when i click on the another tab, let's say about us,
the URL changed to http://example.com/about
but the page appeared is the same as in the home page, http://example.com

yes, it really changed the URL, but it doesn't redirect to the right destination ..

any help would be appreciated.

dtou’s picture

I noticed that RewriteRule works slightly differently if applied in .htaccess file vs Apache config. The configuration from the article may work on other servers but it fails with Apache. Here is example of .htaccess file that works on Apache:

RewriteEngine on
RewriteRule ^folder - [L]            # a subfolder Drupal should ignore
RewriteRule ^file.html - [L]         # a file in root Drupal should ignore
RewriteRule ^(.*) /drupal/$1 [L]

To make thing even more confusing, the same rule written in Apache config file would look different:

RewriteEngine on
RewriteRule ^$ /drupal/ [L] 
RewriteRule ^/folder - [L]            # a subfolder Drupal should ignore
RewriteRule ^/file.html - [L]         # a file in root Drupal should ignore
RewriteRule ^/(.*) /drupal/$1 [L]

Here is the relevant link to Apache mod_rewrite http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule

samwank’s picture

Hello there i tried to create an htaccess file on the root of the wamp as in(drupal 7)dicated i.e

RewriteEngine on
RewriteRule ^folder - [L]            # a subfolder Drupal should ignore
RewriteRule ^file.html - [L]         # a file in root Drupal should ignore
RewriteRule ^(.*) /drupal/$1 [L]

and i got the error :

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

what could i be doing wrong ?