How to remove /drupal from URL in Drupal 7 when in

2019-03-21 10:54发布

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.

3条回答
We Are One
2楼-- · 2019-03-21 11:28

On Apache server, add this to the root .htaccess file.

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

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

$base_url = 'http://www.example.com';
查看更多
冷血范
3楼-- · 2019-03-21 11:30

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

查看更多
贼婆χ
4楼-- · 2019-03-21 11:32

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

... To do this correctly you must first enter the following line (or un-comment the line if >it already exists):

NameVirtualHost *:80

Next you must create the two virtual host entries. One will be similar to the following:

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

The next entry would 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 would only require one virtual host entry & not two.

Additionally, it should be noted that, should you desire to serve a site from a location NOT in your webroot then you would also need a

<Directory></Directory>

entry to tell Apache what access to give to visitors (NOTE: in Linux the Apache user should be made owner of the files [or permissions should be set in a method that still allows the apache user rights to serve the files if you want to avoid giving it ownership])

查看更多
登录 后发表回答