Skip to content

Instantly share code, notes, and snippets.

@twfahey1
Created October 11, 2019 00:32
Show Gist options
  • Save twfahey1/c658ef9e2a5fef16aa64769c8af00404 to your computer and use it in GitHub Desktop.
Save twfahey1/c658ef9e2a5fef16aa64769c8af00404 to your computer and use it in GitHub Desktop.
A .htaccess file for Apache based server to run Drupal in web docroot
# Assuming the Drupal site is installed in /public_html/web, place this in the /public_html folder.
RewriteEngine on
# <!-- Force HTTPS START -->
# If we receive a forwarded http request from a proxy...
RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]
# ...or just a plain old http request directly from the client
RewriteCond %{HTTP:X-Forwarded-Proto} =""
RewriteCond %{HTTPS} !=on
# Redirect to https version
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# <!-- Force HTTPS END -->
# Use web docroot to serve from main domain.
RewriteCond %{REQUEST_URI} !^/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /web/$1
RewriteRule ^(/)?$ web/index.php [L]
# You'll also want to uncomment / add to the .htaccess setting in the /web folder:
# RewriteBase /web
# And in your settings.php (or local-settings.php):
# if (isset($GLOBALS['request']) && '/web/index.php' === $GLOBALS['request']->server->get('SCRIPT_NAME')) {
# $GLOBALS['request']->server->set('SCRIPT_NAME', '/index.php');
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment