Solved

If request on port 80, auto redirect to 443 equivalent - Moodle Course Management System

Posted on 2011-09-14
3
525 Views
Last Modified: 2012-05-12
2.1 Installation of Moodle on a supported virtualmin server running Ubuntu Server 10.04 LTS

I have config file to say that the URI root should be https://mobilek16.net

When users put http://mobilek16.net, they get the error I have shown in screenshot.

I want to auto redirect them if the come in on port 80 but I can't get it to work.

I tried adding at top of index.php something like

<?php
if ($_SERVER['SERVER_PORT']<>443) {
header('Location: https://mobilek16.net');      
}
      ?>

But it is not working either.

Any assistance will be greatly appreciated ;-)
0
Comment
Question by:smetterd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Author Comment

by:smetterd
ID: 36535861
SSL Error message from Moodle LMS
0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 36535956
try:
<?php
if ( intval($_SERVER['SERVER_PORT']) != 443) {
  header('Location: https://mobilek16.net');
  exit;
}
?>

If that does not work, try:
<?php
if ($_SERVER['HTTPS']=='' || strtolower($_SERVER['HTTPS'])=='off' ) {
  header('Location: https://mobilek16.net');
  exit;
}
?>

Open in new window

0
 
LVL 2

Author Comment

by:smetterd
ID: 36535991
Gorgeous... didn't try the second suggestion b/c the first one works!
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question