先装在你的构造网址助手,如果你还没有做它已经:
$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