DrupalDilatant: Forwarding to Drupal Installed in Subdirectory
I prefer installing Drupal in a subdirectory.
- It makes upgrades much easier
- Keeps your root directory less crowded and therefore easier to decipher and maintain
- Keeps Drupal’s htaccess from messing with applications installed on the same server
- It gives you a subdirectory space in your URL to drop in your top keywords for SEO purposes (example homepage address: www.example.com/my_top_keywords/)
But obviously the users who go to your root address have to be forwarded to the install directory.
On an Apache server, I accomplish the forwarding part by putting the following code in an otherwise blank htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule (.*) $1 [L]
RewriteBase /NAME OF THE DIRECTORY TO FORWARD TO
</IfModule>
So, for example, to send users who go to http://projectharambee.org to drupal’s installation at http://projectharambee.org/help_african_women, the code would be:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule (.*) $1 [L]
RewriteBase /help_african_women
</IfModule>
As you see, there’s the code to send users going to another URL to another directory. Just uncomment this part:
What to do with htaccess file that comes with Drupal? That stays in the Drupal’s installation directory. I don’t change that at all, except for this part to avoid SEO issues with duplicate content:
# To redirect all users to access the site WITHOUT the ‘www.’ prefix,
# (http://www.example.com/… will be redirected to http://example.com/…)
# uncomment and adapt the following:
# RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
# RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
Above is line 86-90 in the htaccess that comes with Drupal 6.4
I also use Drupal module GlobalRedirect to avoid the duplicate content issue.
DISCLOSURE: I am NOT a Drupal expert. My posts about Drupal are meant to impart how-to info in plain English on methods that have worked for me. My target audience is people who, like myself, use Drupal as just one of the tools to leverage the Web — hence the name DrupalDilatant.