in ,

Make Drupal Successfully Running at Sub-directory

Make Drupal Successfully Running at Sub-directory

Practical tips to get Drupal 7 running from a sub-directory.

While my Web-server I’am using is Apache, I was able to modify the .htacess files to make it works.

2 .htacess files we need to modify and/or creates if not exist.

  1. First .htacess file which placed into the Document-Root directory (ie. /home/website/public_html directory).
# we will consider drupal sub-directory name is "drupal"
RewriteEngine on
RewriteRule ^$ drupal/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/drupal%{REQUEST_URI} -f
RewriteRule .* drupal/\
# we will consider drupal sub-directory name is "drupal"
RewriteEngine on
RewriteRule ^$ drupal/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/drupal%{REQUEST_URI} -f
RewriteRule .* drupal/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* drupal/index.php?q=$0 [QSA]
[L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* drupal/index.php?q=$0 [QSA]
  1. Second .htacess file which placed into the sub-directory (which contain Drupal installation – ie /home/website/public_html/drupal).
  # Modify the RewriteBase if you are using Drupal in a subdirectory or in a
  # VirtualDocumentRoot and the rewrite rules are not working properly.
  # For example if your site is at http://example.com/drupal uncomment and
  # modify the following line:
  RewriteBase /drupal
  #
  # If your site is running in a VirtualDocumentRoot at http://example.com/,
  # uncomment the following line:
  # RewriteBase /

Clean url must now works fine, also if we need to redirect to non-www we can add Rewrite-rule that provided with Drupal to the Document-Root .htaccess

# we will consider drupal sub-directory name is "drupal"
RewriteEngine on

# To redirect all users to access the site WITHOUT the 'www.' prefix
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]

RewriteRule ^$ drupal/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/drupal%{REQUEST_URI} -f
RewriteRule .* drupal/\
# we will consider drupal sub-directory name is "drupal"
RewriteEngine on
# To redirect all users to access the site WITHOUT the 'www.' prefix
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]
RewriteRule ^$ drupal/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/drupal%{REQUEST_URI} -f
RewriteRule .* drupal/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* drupal/index.php?q=$0 [QSA]
[L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* drupal/index.php?q=$0 [QSA]

Hope That helps,

All best wishes.

What do you think?

Adjustment Drupal and Wordpress for Cloudflare Free HTTPS Switching

Adjustment Drupal and WordPress for Cloudflare Free HTTPS Switching

How to make an open source Load balancer (Stunnel + HAProxy)

How to make an open source Load balancer (Stunnel + HAProxy)