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
Solved

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

Posted on 2011-09-14
3
523 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
  • 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

828 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