1

I am writing a plugin to that will map http://short.com/e9DG to http:/longdomainname.com/longsubpagename

I assume I need to use the config/routes.php but am having struggling to understand how how to set this up. I keep getting 404 as it cannot resolve the url.

As a test I have the foloing code

return array(
    'e9DG' => array('action' => '/cocktailrecipes/ingredients/new'),
);
3

With the registerSiteRoutes hook you can route http://short.com/e9DG requests to any template.

public function registerSiteRoutes()
{
    return array(
        'e9DG' => '/mysection/mytemplate.html',
    );
}

With getUrl and redirect accessible via craft()->request you can set up server redirects:

$url = craft()->request->getUrl();

if ($url == 'http://short.com/e9DG')
{
    craft()->request->redirect('http:/longdomainname.com/longsubpagename', true, 301);
}
| improve this answer | |
1

Take a look at Shortener and Reroute for inspiration as well ( might save you some trouble if you're just trying to write a general URL shortener!)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.