Forum Moderators: phranque

Message Too Old, No Replies

Help http to https

         

chrisguk

6:42 pm on Feb 1, 2010 (gmt 0)

10+ Year Member



I must have spent about 2 hours looking through google and the forum trying to find a solution to my problem. I have detailed what im looking for below:

first of all my folder structure:

index.php
/includes/
/foo/
/bar/buy.php
/bar/product.php

When I am browsing product.php I wish to select the buy button which is pointing to [mydomain.com...] what im trying to achieve is to add to my.htaccess file send any requests for that url to [mydomain.com...]

Is there a possible solution for this?

jdMorgan

8:37 pm on Feb 1, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What have you tried so far? (See forum Charter for more info)

Have you tried the WebmasterWorld search facility? -- There are lots of previous threads on this subject, directly-findable using very-specific search keywords such as redirect "http to https" RewriteCond SERVER_PORT 80 443 SSL RewriteRule [google.com].

Note that this is not a fix for your problem, which is that that 'buy' button link is incorrect, and shoud point to [www,example.com...]

All this will do is to speed up 'fixing' search engine listings which include the incorrect link, and preserve old bookmarks and external link traffic to that link (if any). URLs are defined on your HTML pages, and any real 'fixes' for them belong on those pages.

Jim

chrisguk

8:55 pm on Feb 1, 2010 (gmt 0)

10+ Year Member



Hi Jim,

On this occasion I did consult the forum charter in some depth. I think I have come up with my own work around using php as follows:

I have a config.php file that is included in my header.php all I did was append the following script to the config file:

$ssl= 'https://' . $_SERVER['HTTP_HOST'];

Then:

with the buy.php, each link that needed to goto ssl, of which there are only 3 per page I inserted this:

<a href="<?php echo $ssl; ?>/foo/buy.php">BuyME</a>

Whats your opinion on my own fix i.e. any security risks?

Chris

jdMorgan

9:25 pm on Feb 1, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Fixing the links is really the way to go, so that's a better solution, although it might be much clearer to simply put the "https://$_SERVER['HTTP_HOST']" in the page-code itself.

Jim

chrisguk

9:50 pm on Feb 1, 2010 (gmt 0)

10+ Year Member



Hi,

Normally I would use that simpler solution but I tend to test on a local server so its easy to disable ssl my way:

$ssl= 'https://' . $_SERVER['HTTP_HOST']; //www
$ssl= 'http://' . $_SERVER['HTTP_HOST']; //local

Chris

chrisguk

9:52 pm on Feb 1, 2010 (gmt 0)

10+ Year Member



Hi,

oh see what you mean.


in the config.php file:

like so:

$ssl= 'https://$_SERVER['HTTP_HOST'];

jdMorgan

2:07 pm on Feb 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well no, I meant put the full protocol and servername de-referencing in each 'link-making' line of your PHP code, but with your local development scenario, there is an advantage to your current approach.

Jim