Drupal is installed in folder /drupal
I want the website to display on url http://domain.com and not http://domain.com/drupal

I have tried various suggestions from over the internet as well as the drupal documentation I found on this (6-8 years old) to change both .htaccess in the root directory as well as change the $base_url variable in default/settings.php
The latter action messes up the website (so I commented out the base_url again).
Whatever I change in my .htaccess file, I keep seeing http://domain.com/drupal
The only thing I accomplished is that http://domain.com takes the visitor to http://domain.com/drupal

Options +FollowSymlinks
RewriteEngine on
#invisibly redirect to subfolder /drupal
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ drupal
#leave out 'www'
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=302,NC,L]

I would be delighted if anyone can point me out how to indeed redirect without the subfolder showing up in the url.

Comments

JohanLingen’s picture

I solved it by using:

Options +FollowSymlinks
RewriteEngine on

# .htaccess primary domain to subfolder redirect
# also updated ../drupal/sites/default/settings.php with $base_url = 'http://mydomain.com'; (first make folder writeable)
# First redirect any file requests without '/drupal/' in the URL to the subfolder /drupal/
RewriteCond %{HTTP_HOST} !^(www.)?mydomain.com/admin$
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteCond %{REQUEST_URI} !^/drupal/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /drupal/$1

# Then redirect http://www.mydomain.com to http://mydomain.com
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301,NC]

# Lastly refer either www.mydomain.com (shouldn't be the case anymore because of rule above) or mydomain.com to ../drupal/index.php
RewriteCond %{HTTP_HOST} !^(www.)?mydomain.com/admin$
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteRule ^(/)?$ drupal/index.php

Notice that I also changed sites/default/settings.php.

Please note that I noticed today that I lost admin access. I am not yet sure if it is related.

JohanLingen’s picture

For my solution to the admin panel problems, please see https://www.drupal.org/node/2471929

danievdm’s picture

Thanks Johan it worked for me with Drupal 8 after struggling through many other solutions elsewhere that were not working. I have a subdomain set pointing to the /drupal directory and use that sub-domain to access my admin panel.

shakilahmad’s picture

I used this method it's working but now I am not able to see all the images on my site.

karolus’s picture

For most of my installs, I have Drupal running from subfolders. Here is what I do:

settings.php

Uncomment and modify this line:
# $base_url = 'http://www.example.com'; // NO trailing slash!

.htaccess (in your subfolder)

Unless there are server/web host-specific items to add, this can be left alone

.htaccss (in Web root)

Options -Indexes
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} !^www\.[yourdomain]\.[your TLD]$ [NC]
RewriteRule .* http://www..[yourdomain].[your TLD]/	[L,R=301]
RewriteRule ^$ production/index.php	[L]
RewriteCond %{DOCUMENT_ROOT}/[subfolder]%{REQUEST_URI} -f
RewriteRule .* [subfolder]/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .*[subfolder]/index.php?q=$0 [QSA]

Hope this helps.

bhupendra_kanojiya’s picture

Thanks, it works perfectly.