Looking for software experts?
Need an expert advice on software development? Need consulting work done in time and at high standards? Tremend has the right solution for you.

We can provide expertise in:
  •    » high traffic and complex content website infrastructures using Java, PHP or .NET. More here ...
  •    » mobile applications for iPhone, Android or J2ME. More here ...

For an enquiry, send an email to contact [at] tremend [dot] ro.

How to move Drupal to a subdirectory and keep the links

October 20th, 2009 by Bogdan Nitulescu in Drupal

The usual way for Drupal is to have it live in the root of your web site. It’s all nice if the only thing on your site is Drupal, but it gets very cluttered when you have other top-level directories.

One customer had his corporate site at, say, “www.example.com“, and his customer support pages at “www.example.com/support“.  We wanted to keep the application in the “support” directory, move all the drupal directories under “corporate“. And keep the old links working.

First we had to let Drupal know that, even if it’s been relocated to “corporate”, the URL still remains the same. Do it in “corporate/sites/default/settings.php“:

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

Then tell Apache that Drupal has moved. Put these rewrite rules in .htaccess in the root of your web site.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  RewriteEngine on
 
  # Rewrite www.example.com to the Drupal home page: www.example.com/corporate/index.php
  RewriteRule ^$ corporate/index.php [L]
  # Let Drupal process paths like www.example.com/corporate/about
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^corporate/(.*)$ corporate/index.php?q=$1 [L,QSA]
 
  # Search for real Drupal files that moved, 
  #  (e.g. www.example.com/flash/intro.swf to www.example.com/corporate/flash/intro.swf)
  RewriteCond %{DOCUMENT_ROOT}/corporate/$1 -f
  RewriteRule ^(.*)$ corporate/$1 [L]
 
  # Let Drupal process all paths that are not real files and directories, like www.example.com/about
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ corporate/index.php?q=$1 [L,QSA]
 
  # What's left are real non-Drupal pages and directories, like www.example.com/support
DZoneGoogle ReaderYahoo MessengerRedditEmailDelicious

Related posts

  • Drupal Commerce for ePayment module
    Inspired by Drupal philosophy of contributing code and modules for the community, we have released a module that provides ePayment support in Drupal Commerce. Available here. Just install the module,...
  • Taxonomy additions Drupal module
    Our first Drupal module: http://drupal.org/project/taxonomy_additions ads various additions to the core Taxonomy module. Meet Andrei (amateescu at tremend.ro) in Brussels at Drupal Developer Days 2011,...
  • Xaraya to Drupal Migration Script
    Using some functionalities from this script I managed to port a Xaraya 1.4 installation to Drupal 6.13. The script performs the following tasks: imports users imports articles and comments ...
  • Tremend 6 years
    Tremend is now 6 years old, a new year of projects and challenges. So what is new in this past year? We've extended our expertise in technologies such as Drupal and Grails. Published custom modules...
  • Spring and Tiles – presentation tier in http://www.123urban.ro
    Presentation tier in 123urban - Spring comes to the rescue as usual with its embedded support for Tiles. Basically, the only setting is to change your viewResolver in your -servlet.xml from JstlView...
.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.