Skip to content

Instantly share code, notes, and snippets.

@Stenerson
Created December 14, 2013 14:18
Show Gist options
  • Save Stenerson/7959689 to your computer and use it in GitHub Desktop.
Save Stenerson/7959689 to your computer and use it in GitHub Desktop.
One of my projects recently migrated domains over a weekend. I was concerned that many of the users (who are mostly very non-technical and use tablets to access the site) would panic and stop using the site if they didn't already know about the new domain. I could have done a permanent redirect to the index of the new domain but I know some user…
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Redirect extends CI_Controller {
function __construct() {
parent::__construct();
}
public function index()
{
$destination_uri = uri_string();
// Stop auto redirect once it's 2014
// Hopefully this annoys people enough to change their bookmarks before the site is totally gone
// Don't worry - there's still a link
$year = (int) date('y');
$auto_redirect = ($year <= 13);
$this->data['destination_base_url'] = "http://newsite.com/";
$this->data['destination_uri'] = $destination_uri;
$this->data['auto_redirect'] = $auto_redirect;
// Loads css and sets up basic html scaffold and content div
$this->load->view('common/noAuthHeader',$this->data);
// Redirector view (redirector.php)
$this->load->view('common/redirector',$this->data);
// Loads any required js and closes content, body, html
$this->load->view('common/noAuthFooter',$this->data);
}
} // end of Redirect
/* End of file redirect.php */
/* Location: ./application/controllers/redirect.php */
<div class="row-fluid">
<div class="span6 offset3 center-align">
<h2>This site has moved!</h2>
<h4>It is now located at <a href="<?=$destination_base_url.$destination_uri?>"><?=$destination_base_url?></a></h4>
<p>Please update your bookmarks to the new site.</p>
<?php
if ($auto_redirect) {
?>
<p>You will be automatically redirected in 10 seconds.</p>
<script type="text/javascript">
setTimeout(function () {
window.location.href = "<?=$destination_base_url.$destination_uri?>"; //will redirect to the correct page on the new site
}, 10000); //will call the function after 10 secs.
</script>
<?php
}
?>
</div>
</div>
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// default controller route is required
$route['default_controller'] = "redirect";
//Handle all requests through the redirect controller
$route['(.*)'] = "redirect/index/$1";
/* End of file routes.php */
/* Location: ./application/config/routes.php */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment