Web Hosting Geeks | Web Hosting Experts
Need help? Call us 1(866)TOP-HOST

14361 reviews 1715 hosting providers

Questions & Answers

Redirect browser to https in php

May 11, 2012 by chris
hello everyone

I have an ecommerce website that uses payment gateway for online payments. I have SSL installed, and I want to redirect the browser to https instead of http.
Can someone here please tell me how to do this in php?

2 Answers

0 votes
May 11, 2012 by expert
Function to redirect the browser to 'https'in PHP
function redirectToHTTPS()
     $redirect= "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
0 votes
May 11, 2012 by WebGuru
if you want to redirecting the whole website to 'https' it's easier to do it using .htaccess
this is the code tou should use
  RewriteEngine On
  RewriteCond %{HTTPS} !on
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}