先裝在你的構造網址助手,如果你還沒有做它已經:
$this->load->helper('url');
那麼當你需要重定向,你可以簡單地調用:
$s3_url = "https://mywebapp.s3.amazonaws.com/products/image1.jpg";
// you can omit the last two parameters for the default redirect
redirect($s3_url, 'location', 301);
我猜你想這是我的解決方案
<?php if (!defined('BASEPATH')) die();
class Img extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper('url');
// this is the db model where you store the image's urls
$this->load->model('images_model', 'img_m');
}
// accessed as example.com/img/<image_id>
// redirects to the appropiate s3 URL
public function index()
{
// get the second segment (returns false if not set)
$image_id = $this->uri->segment(2);
// if there was no image in the url set:
if ($image_id === false)
{
// load an image index view
$this->load->view('image_index_v');
exit;
}
$url = $this->img_m->get_url($image_id);
// get_url() should return something like this:
$url = "https://mywebapp.s3.amazonaws.com/products/image1.jpg";
// then you simply call:
redirect($url, 'location', 301);
}
}
爲什麼不直接使用S3鏈接直接使用S3鏈接什麼時候需要它?我們至少需要知道你想達到什麼目的。 – xiankai
我知道它不需要,但我只是認爲這種URL重定向會顯得更專業,而且我希望我的所有網址具有相同的原點以獲得更好的外觀。 –
然後你想要的不是url重定向,它是域掩碼。 http://en.wikipedia.org/wiki/Domain_Masking – xiankai