Last active
January 3, 2016 14:19
-
-
Save tannerhodges/8475351 to your computer and use it in GitHub Desktop.
Redirect URLs within the Lithium framework via simple routes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace app\controllers; | |
/** | |
* Redirects Controller | This controller is designed to work in conjunction | |
* with `routes.php` by routing the desired URL to a new one. E.g., | |
* redirecting '/keepinitreal' to the static directory '/mycard/loyalty-card'. | |
* | |
* ```php | |
* Router::connect('/keepinitreal', array('Redirects::index', 'args' => array('/mycard/loyalty-card'))); | |
* ``` | |
* | |
* In the case of permanent 301 redirects (e.g., changing the URL of '/grow- | |
* us' to '/franchise') the `.htaccess` file ought to be utilized instead. It | |
* will be a) faster and b) recognized by search engines. | |
* | |
* Note: The redirect destination *should* be an absolute URL. A relative URL | |
* will work, but absolute is best practice. | |
* | |
* ``` | |
* # Change URL of '/grow-us' page to '/franchise' | |
* Redirect 301 /grow-us http://yeahburger.com/franchise | |
* ``` | |
*/ | |
class RedirectsController extends \lithium\action\Controller | |
{ | |
/** | |
* Redirect method | |
* @todo Consider validating URL before sending them off? | |
*/ | |
public function index() | |
{ | |
// Get destination from arguments; default to home page | |
$args = func_get_args(); | |
$destination = !empty($args[0]) ? $args[0] : '/'; | |
// Redirect to destination URL | |
$this->redirect($destination); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment