How to remove / drupal from a URL in Drupal 7 when the installation is in a related subdirectory

In Drupal 6, I was able to successfully install Drupal in the drupal subdirectory, and then link to the site without using example.com/drupal. In Drupal 6, to make this work, I did the following: - Created a .htaccess file in the root directory where / drupal was created. File contents:

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

The drupal/sites/default/settings.php file has been drupal/sites/default/settings.php , for which $ base_url is defined as: $base_url = 'http://example.com';

When I try to do the same for Drupal 7, only the first page can be displayed, all pages fail pretty badly (or only appear on the first page). I also tried to uncomment the RewriteBase lines in /drupal/.htaccess. First I tried RewriteBase /drupal , and then I tried RewriteBase / . But both attempts failed. I never had to do this with D6, but I thought I would eliminate this possible solution.

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

So, how can you install Drupal 7 in a subdirectory and then run it from this directory without the directory name in the url? Note. I install Drupal 7 in a subdirectory, as it makes it easier to upgrade between new versions of the Drupal 7 kernel.

+4
source share
3 answers

Try the following:

 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 the example.com directory. You do not need to change drupal7.htaccess

+4
source

On the Apache server, add it to the .htaccess file.

RewriteEngine on RewriteRule (. *) Drupal / $ 1 [L]

Update the drupal settings.php file (in the / drupal / site / default / directory) so that the line $ base_url reads:

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

I answered a very similar question about this: Two Drupal installations on the same server My answer to your question is the same, I recommend abandoning the rewrite method in favor of the virtual host method, as described below (this is just an excerpt from what I answered in the link above):

... To do this correctly, you must first enter the following line (or not comment on the line if it already exists):

 NameVirtualHost *:80 

Then you must create two virtual host entries. One of them will look like the following:

 <VirtualHost *:80> ServerName your.url.fortheroot ServerAlias alternate.url.fortheroot DocumentRoot "/path/to/webroot" </VirtualHost> 

The next entry will be similar to the following.

 <VirtualHost *:80> ServerName your.url.forthesubfoldertest ServerAlias alternate.url.forthesubfolder DocumentRoot "/path/to/webroot/test" </VirtualHost> 

...

In your case, however, you only need one virtual host entry, not two.

In addition, it should be noted that if you want to serve the site from a NOT location in your feed, you will also need

 <Directory></Directory> 

to tell Apache what access to give visitors (NOTE: on Linux, the Apache user must be the owner of the files [or permissions must be set in a method that still allows apache user rights to serve the files if you want to not give him ownership))

+1
source

All Articles