Page 1 of 1
HTTP to HTTPS redirect?
Posted: Mon Dec 07, 2009 1:24 pm
by rockybloggs
Hi everyone, this is my first post. I am having trouble with a redirect I am trying to put on an a page of mine. I need to redirect visitors from my site, which is an http site, to an https page on another site.
I can get it to redirect to the desired https page, but it appends this on the the end of the url:
Here is the code I am using.
Code: Select all
<?php
if ($_SERVER['SERVER_PORT']!=443)
{
$url = "https://securesite.com". $_SERVER['SERVER_NAME'] . ":443";
header("Location: $url");
}
?>
So when it redirects the URL looks like this:
- https://securesite.commyhttpsite.com:443
Can anyone help me? I have just started to get into php, like a week ago, and I thought I could do this as it would be easy!
Thanks
Re: HTTP to HTTPS redirect?
Posted: Mon Dec 07, 2009 1:34 pm
by AbraCadaver
Where do you want to redirect?
Re: HTTP to HTTPS redirect?
Posted: Mon Dec 07, 2009 1:54 pm
by rockybloggs
AbraCadaver wrote:Where do you want to redirect?
Its to a secure order page. I took out the original url in the code, I replaced it with securesite.com.
Code: Select all
<?php
if ($_SERVER['SERVER_PORT']!=443)
{
$url = "https://securesite.com". $_SERVER['SERVER_NAME'] . ":443";
header("Location: $url");
}
?>
Rocky
Re: HTTP to HTTPS redirect?
Posted: Mon Dec 07, 2009 1:59 pm
by AbraCadaver
rockybloggs wrote:AbraCadaver wrote:Where do you want to redirect?
Its to a secure order page. I took out the original url in the code, I replaced it with securesite.com.
Code: Select all
<?php
if ($_SERVER['SERVER_PORT']!=443)
{
$url = "https://securesite.com". $_SERVER['SERVER_NAME'] . ":443";
header("Location: $url");
}
?>
Rocky
Yeah I got that, but what's with the $_SERVER['SERVER_NAME']?
Why not just:
Code: Select all
$url = "https://securesite.com";
header("Location: $url");
Re: HTTP to HTTPS redirect?
Posted: Mon Dec 07, 2009 2:00 pm
by pickle
You don't need to specify port 443. HTTPS traffic is automatically (by default) served over port 443, just like plain HTTP traffic is served over port 80.
Re: HTTP to HTTPS redirect?
Posted: Mon Dec 07, 2009 5:08 pm
by rockybloggs
Yeah I got that, but what's with the $_SERVER['SERVER_NAME']?
Why not just:
Code: Select all
$url = "https://securesite.com";
header("Location: $url");
Thanks that did it! I dont know why I thought that, I just figured it would need it. It was in the others I found around the internet for https redirects.
Thanks again!