我有一系列Rackspace云文件存储的CDN URL,它们引用了一个HTTP地址,我希望将它们转换为HTTPS等效。将Rackspace Cloud文件转换为HTTP到HTTPS的CDN URL
Rackspace的云文件CDN网址的格式如下:
http://c186397.r97.cf1.rackcdn.com/CloudFiles Akamai.pdf
而SSL相当于这个网址是:
https://c186397.ssl.cf1.rackcdn.com/CloudFiles Akamai.pdf
到的变化网址是(source):
- HTTP变得HTTPS
- 第二URI段(在该例子 'R97')变为 'SSL'
在 'R00' 部分似乎在长度上变化(如一些是 'R6'等等),所以我无法将这些URL转换为HTTPS。这是我到目前为止的代码:
function rackspace_cloud_http_to_https($url)
{
//Replace the HTTP part with HTTPS
$url = str_replace("http", "https", $url, $count = 1);
//Get the position of the .r00 segment
$pos = strpos($url, '.r');
if ($pos === FALSE)
{
//Not present in the URL
return FALSE;
}
//Get the .r00 part to replace
$replace = substr($url, $pos, 4);
//Replace it with .ssl
$url = str_replace($replace, ".ssl", $url, $count = 1);
return $url;
}
但是,这对于第二个段的长度不同的URL无效。
任何想法赞赏。
刚刚经过测试,它适用于不同长度的零件。谢谢。 – 2012-03-26 16:46:01
干杯,自从我把它写下来以后,可能会有一些语法错误,但是很高兴它可以工作! – jessica 2012-03-26 16:48:02