generaledx

Force HTTPS redirection with Apache

NOTE: We are in the process of modifying the file structure and configuration for many Bitnami stacks. On account of these changes, the file paths stated in this guide may change depending on whether your Bitnami stack uses native Linux system packages (Approach A), or if it is a self-contained installation (Approach B). To identify your Bitnami installation type and what approach to follow, run the command below:

 $ test ! -f "/opt/bitnami/common/bin/openssl" && echo "Approach A: Using system packages." || echo "Approach B: Self-contained installation."

The output of the command indicates which approach (A or B) is used by the installation, and will allow you to identify the paths, configuration and commands to use in this guide. Refer to the FAQ for more information on these changes.

Approach A: Bitnami installations using system packages

Edit the configuration file /opt/bitnami/apache2/conf/vhosts/edx-lms-vhost.conf and find the lines containing rewrite rules. Typically, it will look like this:

# BEGIN: Redirection to Studio CMS
# This is useful for linking to the edX Studio (CMS) via documentation or external services (e.g. Launchpads)
RewriteEngine On
RewriteRule ^/edx-studio(/.*)? http://%{SERVER_NAME}:18010/ [R,L]
# END: Redirection to Studio CMS

Update the above content with additional rules to force HTTPS redirection, so that it looks like this:

# BEGIN: Redirection to Studio CMS
# This is useful for linking to the edX Studio (CMS) via documentation or external services (e.g. Launchpads)
RewriteEngine On
RewriteRule ^/edx-studio(/.*)? http://%{SERVER_NAME}:18010/ [R,L]
# END: Redirection to Studio CMS

# BEGIN: Force HTTPS redirection
RewriteCond %{HTTPS} !=on
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
# END: Force HTTPS redirection

Approach B: Self-contained Bitnami installations

Edit the configuration file /opt/bitnami/apps/edx/conf/httpd-lms.conf and find the lines containing rewrite rules. Typically, it will look like this:

# Enable some basic redirections
RewriteEngine On
RewriteRule ^/edx-studio(/.*)? http://%{SERVER_NAME}:18010/ [R,L]

Update the above content with additional rules to force HTTPS redirection, so that it looks like this:

# Enable some basic redirections
RewriteEngine On
RewriteRule ^/edx-studio(/.*)? http://%{SERVER_NAME}:18010/ [R,L]
# Force HTTPS redirection
RewriteCond %{HTTPS} !=on
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]

After modifying the Apache configuration files, restart Apache to apply the changes.

Last modification November 10, 2021