[英]Converting Rackspace Cloud Files CDN URLs from HTTP to HTTPS
我存儲了一系列Rackspace Cloud Files CDN URL,這些URL引用一個HTTP地址,我想將它們轉換為等效的HTTPS。
Rackspace Cloud Files CDN URL的格式如下:
http://c186397.r97.cf1.rackcdn.com/CloudFiles Akamai.pdf
此URL的SSL等效項為:
https://c186397.ssl.cf1.rackcdn.com/CloudFiles Akamai.pdf
URL的更改為( source ):
“ 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。
任何想法表示贊賞。
我知道這很舊,但是如果您使用的是此庫: https : //github.com/rackspace/php-opencloud可以在對象上使用getPublicUrl()方法,則只需使用以下命名空間
use OpenCloud\ObjectStore\Constants as Constant;
// Code logic to upload file
$https_file_url = $response->getPublicUrl(Constant\UrlType::SSL);
嘗試這個:
function rackspace_cloud_http_to_https($url)
{
$urlparts = explode('.', $url);
// check for presence of 'r' segment
if (preg_match('/r\d+/', $urlparts[1]))
{
// replace appropriate segments of url
$urlparts[0] = str_replace("http", "https", $urlparts[0]);
$urlparts[1] = 'ssl';
// put url back together
$url = implode('.', $urlparts);
return $url;
}
else
{
return false;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.