HTTPアドレスを参照する一連のRackspaceCloudFiles CDN URLを保存しており、それらを同等のHTTPSに変換したいと思います。
Rackspace Cloud FilesCDNURLは次の形式です。
http://c186397.r97.cf1.rackcdn.com/CloudFiles Akamai.pdf
また、このURLに相当するSSLは次のようになります。
https://c186397.ssl.cf1.rackcdn.com/CloudFiles Akamai.pdf
URLへの変更は次のとおりです(ソース):
- HTTPはHTTPSになります
- 2番目の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;
}
ただし、これは、2番目のセグメントの長さが異なるURLでは機能しません。
どんな考えでもありがたいです。