By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,962 Members | 1,998 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,962 IT Pros & Developers. It's quick & easy.

Hi how to redirect http to https using php

100+
P: 121
Hi everybody,
Iam facing problem with redirecting http: connection to https:

Here iam Running my scripts on Apache using normal http request...
but i want to redirect my http url to https url for securing data
How should i do this...
don't say like redirect("Location:https://localhost/index.php");
because i tried It is not working...

Please let me know ..? is there any another way to do this...

If you give reponse for this .Iam very thankful and it will be great.......

Thanks & regaurds,

bettadpur
Dec 24 '07 #1
Share this Question
Share on Google+
2 Replies


P: 30
have you tried header() and remember that is has to be the first thing before anything is outputted?
Dec 24 '07 #2

nathj
Expert 100+
P: 938
Hi everybody,
Iam facing problem with redirecting http: connection to https:

Here iam Running my scripts on Apache using normal http request...
but i want to redirect my http url to https url for securing data
How should i do this...
don't say like redirect("Location:https://localhost/index.php");
because i tried It is not working...

Please let me know ..? is there any another way to do this...

If you give reponse for this .Iam very thankful and it will be great.......

Thanks & regaurds,

bettadpur
Hi,

First of all if you want to use the header for anything at all it needs to happen before any output on the page and that includes whitespace!

Second, the more specific issue of the https. Do you have an SSL certifcate in place? If so most host will provide you with the required .htacess lines required to use the secure server. It's normally something like:
Expand|Select|Wrap|Line Numbers
  1. RewriteEngine On
  2. RewriteCond %{SERVER_PORT} !^443$
  3. RewriteRule ^(.*)$ __NEW URL__/$1 [R]
  4.  
The new url will contain https:// as the start of the address.

I admit I have only limited experience with this and this based on a particular host company using a certain type of SSL certificate. So it may be off the wall. Hopefully it will be enough to point you in the right direction.
Cheers
nathj
Dec 24 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.