Trying to redirect https://my-domain.com to https://my-domain.com/login

Keywords: Moodle - AWS - How to - Other
Description:
I am trying to redirect from https://my-domain.com to https://my-domain.com/login.

I already did the http t https redirection according to :
https://docs.bitnami.com/aws/apps/moodle/administration/force-https-apache/
and it works fine.

I changed the rewrite rule to

RewriteRule ^/(.*) https://my-domain.com/login/ [R,L]

in both bitnami-conf & bitnami-ssl.conf (/opt/bitnami/apache2/conf/bitnami) and restarted all resvices using:
sudo /opt/bitnami/ctlscript.sh start

and still it does not work.

any chance I am missing something?

Hi @boazng

Thanks for using Bitnami Moodle!

and restarted all resvices using:
sudo /opt/bitnami/ctlscript.sh start

You should be using sudo /opt/bitnami/ctlscript.sh restart instead :slightly_smiling_face:

If that does not resolve your issue, we have a Support Tool that will gather relevant information for us to analyze your configuration and logs. Could you please execute it on the machine where the stack is running by following the steps described in the guide below?

Please note that you need to paste the code ID that is shown at the end.

Best regards,
Jose Antonio Carmona


Was my answer helpful? Click on :heart:

I tried your suggestion, restarting the services, but it did not solve the issue.
I run the Bitnami support tool:

5b3377df-debb-e55a-cae0-d278bf753a7e

Thank you for your assistance

Hi @boazng

Thanks for running the bnsupport-tool. I have checked your configuration and it seems to have some wrong/incongruent settings:

  1. Your /opt/bitnami/apache/conf/bitnami/bitnami-ssl.conf (used for HTTPs) defines VirtualHost intended to handle regular HTTP connections. Additionally, the redirection rule won’t be executed:
...
Listen 443
SSLProtocol all -SSLv2 -SSLv3
SSLHonorCipherOrder on
SSLCipherSuite "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !EDH !RC4"
SSLPassPhraseDialog  builtin
SSLSessionCache "shmcb:/opt/bitnami/apache/logs/ssl_scache(512000)"
SSLSessionCacheTimeout  300

- <VirtualHost _default_:80>
-    DocumentRoot "/opt/bitnami/apache2/htdocs"
-    RewriteEngine On
-    RewriteCond %{HTTPS} !=on
-    RewriteCond %{HTTP_HOST} !^knoYYYYYYY.XXXXXXXXXXXXXXXX.com$
-    RewriteCond %{HTTP_HOST} !^www.knoYYYYYYY.XXXXXXXXXXXXXXXX.com$
-    RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
-    RewriteRule ^/(.*) https://knoYYYYYYY.XXXXXXXXXXXXXXXX.com/login/ [R=301,L]
- </VirtualHost>

<VirtualHost _default_:443>
  DocumentRoot "/opt/bitnami/apache/htdocs"

- RewriteEngine On 
- RewriteCond %{HTTPS} !=on # --> This will never be executed, 443 is the default port for HTTPs connections
- RewriteRule ^/(.*) https://knoYYYYYYY.XXXXXXXXXXXXXXXX.com/login/ [R=301,L]

  SSLEngine on
  SSLCertificateFile "/opt/bitnami/apache/conf/bitnami/certs/server.crt"
  SSLCertificateKeyFile "/opt/bitnami/apache/conf/bitnami/certs/server.key"
...
  1. Something similar happens to your apache/conf/vhosts/moodle-https-vhost.conf (used for HTTPs). Perform the following changes:
<VirtualHost 127.0.0.1:443 _default_:443>

  ServerAlias *
+ RedirectMatch ^/$ /login/
  SSLEngine on
  SSLCertificateFile "/opt/bitnami/apache/conf/bitnami/certs/server.crt"
  SSLCertificateKeyFile "/opt/bitnami/apache/conf/bitnami/certs/server.key"
  DocumentRoot /opt/bitnami/moodle

  <Directory "/opt/bitnami/moodle">
    Options -Indexes +FollowSymLinks -MultiViews
    AllowOverride All
    Require all granted
  </Directory>
</VirtualHost>

-  <VirtualHost _default_:80>
-    DocumentRoot "/opt/bitnami/apache2/htdocs"
-    RewriteEngine On
-    RewriteCond %{HTTPS} !=on
-    RewriteCond %{HTTP_HOST} !^knoYYYYYYY.XXXXXXXXXXXXXXXX.com$
-    RewriteCond %{HTTP_HOST} !^www.knoYYYYYYY.XXXXXXXXXXXXXXXX.com$
-    RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
-    RewriteRule ^/(.*)$ https://knoYYYYYYY.XXXXXXXXXXXXXXXX.com/login/ [R,L]
-  </VirtualHost>

After applying the changes, check that the syntax is OK and restart Apache:

$ sudo apachectl -t
Syntax OK

$ sudo /opt/bitnami/ctlscript.sh restart apache

Best regards,
Jose Antonio Carmona


Was my answer helpful? Click on :heart:

1 Like

Thank you.
I removed all the red lines, added the green line.
it works perfectly.

Glad to see you were able to solve your issue! We are marking the previous answer as “Solution” and this topic as “Closed”.

If you have any other questions, please do not hesitate to let us know. Feel free to create a new topic referencing this one if necessary.

Best regards,
Jose Antonio Carmona


Was my answer helpful? Click on :heart: