Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove /drupal from URL in Drupal 7 when installation is in the associated sub-directory

In Drupal 6 I was able to successful install Drupal in a subdirectory called drupal and then reference the site without having to use example.com/drupal. In Drupal 6 to get this to work I did the following: - Created an .htaccess file in the root directory where /drupal was created. The file contents was:

Options -Indexes
RewriteEngine On
RewriteRule ^$ drupal/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ drupal/$1

Updated the drupal/sites/default/settings.php file to have the $base_url defined as: $base_url = 'http://example.com';

When I try and do the same thing for Drupal 7, only the front page can be displayed, all the pages fail quite horribly (or only display the front page). I have also tried uncommenting the RewriteBase lines in /drupal/.htaccess. First I tried RewriteBase /drupal and then tried RewriteBase /. But both attempts failed. I never needed to do this with D6, but I thought I would rule out this possible fix.

I am currently testing the new Drupal 7 install using xampp (version 1.7.4) with the example.com site under htdocs (i.e. xampp/htdocs/example.com/drupal). The Drupal 6 site is within the same xampp installation, but of course with a different directory path (e.g. xampp/htdocs/d6example.com/drupal). Note that I also have the Drupal 6 installation running on a production server with only the $base_url variable value changed.

So, how can you install Drupal 7 in a subdirectory and then run it from that directory without having the directory name in the URL? Note I am installing Drupal 7 in a subdirectory as it allows for easier upgrading between new releases of the Drupal 7 core.

like image 463
spots Avatar asked Jan 19 '23 23:01

spots


1 Answers

Try with this :

RewriteEngine On

RewriteBase /example.com
RewriteRule ^$ drupal/ [L]

# rewrite rules for drupal files
RewriteCond %{DOCUMENT_ROOT}/example.com/drupal/$1 -f
RewriteRule ^(.*)$ drupal/$1 [L,QSA]

# rewrite rules for drupal paths
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ drupal/index.php?q=$1 [L,QSA]

Put this .htaccess file in example.com directory. You don't have to modify drupal7 .htaccess

like image 86
soju Avatar answered Jan 29 '23 16:01

soju