Installing and upgrading help

http to https rewrite/redirect

 
This discussion has been locked because a year has elapsed since the last post. Please start a new discussion topic.
Picture of Adam Scarboro
http to https rewrite/redirect
 

Ok this may be more of a Linux question instead of a Moodle one but here goes.  I've got my new dev site up and running.  Its 2.8.2+ (Build: 20150123) running on CentOS 7.  Its a migration from a windows server and an upgrade.  Once that was complete I decided to force it to be https.  I did this by simply referencing the correct certs in /etc/httpd/conf.d/ssl.conf and then in the moodle config.php file setting $CFG->wwwroot = 'https://mymoodle.bla'  It all seems to have worked perfectly and if I go to https://mymoodle.bla everything is good and all parts of the site stay https as you move around.

 

Only issue is http.  If I go to http://mymoodle.bla I'm greeted with the message "For security reasons only https connections are allowed, sorry." in bubble.  Personally I'm kinda ok with that smile but at any rate I'm trying to make it so that if someone goes to the http site they will automatically redirect to https.  I've tried adding each of the following to /etc/httpd/conf/httpd.conf:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Maybe I have something wrong or not turned on but after restarting httpd this simply causes main page to fail to display.  Then I commented that part out and tried.

Redirect permanent / https://mymoodle.bla/ 

This also simply failed to display in IE however Chrome was slightly more helpful and said it was causing a redirect loop when trying to hit the http site.

 

Two other bits of info that I don't think matter but I guess they could.  In the moodle site under the http security section I don't have the "Use HTTTPS for logins" checked.  The whole site is working https so it seemed unnecessary.  Also my moodle code lives at /var/www/html/moodle/  In order to make it so users don't have to add /moodle at the end of the url I changed the DocumentRoot in httpd.conf to be "/var/www/html/moodle"

 

Any help would be appreciated.

 

 

 

 


 
Average of ratings: -
Picture of Adam Scarboro
Re: http to https rewrite/redirect
 


And I'm an idiot.  In my post above I had typed the following:

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

 

Too bad that isn't actually what I had typed in the httpd.conf file. While trying other things I discovered I had not only forgot to load mod_rewrite but also added an extra S and incorrectly typed.

RewriteRule (.*) https://%{HTTPS_HOST}%{REQUEST_URI}

 

Oh well, lesson learned.  Hopefully this helps someone.

 

 

 
Average of ratings: Useful (1)