RSS

Force redirect to SSL secure page

Sat, Sep 20, 2008

Server / Web Apps

Here’s a php code snippet to force the page to https instead of http. You can use a self-signed SSL certificate on your OS X testing server.

[sourcecode language=’php’]

[/sourcecode]

, ,

This post was written by:

- who has written 48 posts on Mac Lab: An Apple Macintosh OS X, Mac & PC Blog.


2 Comments For This Post

  1. Preston Lanier Says:

    Sorry, I am a new to Terminal. Can you tell me which file this is? I am trying to force http to https redirect on Leopard Server and I have yet to find out which file it is. Any help would be very much appreciated. Thanks!

  2. Barry Bourland Says:

    Hi Preston —

    You would need to add this PHP code snippet to the top of the .php page you are working with. It doesn’t have to do with Terminal. Just add it to the top of your xyz.php page.

    < ?php // force redirect to SSL secure page if($_SERVER['SERVER_PORT'] != '443') { header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); exit(); } ?>

Leave a Reply