<p>I'd try and avoid the <code>routes.php</code> route (pun intended).  There isn't any need to get Craft involved in a redirect when your web server (Apache?) can handle it much faster.</p>

<p>If you're using Apache, then adding something like this to your public <code>.htaccess</code> file should do the trick:</p>

<pre><code>RewriteRule ^fiveminutes$ /5minutes [NC,R=301,L]
</code></pre>

<p><strong>Update:</strong></p>

<p>Missed the part where you said this was in a plugin.  In that case you'd want to setup something like this in your main plugin's class file:</p>

<pre><code>public function registerCpRoutes()
{
    return array(
        'fiveminutes' =&gt; array('action' =&gt; 'myPluginController/fiveMinuteRedirect'),
   );
}
</code></pre>

<p>Then from your <code>MyPluginController.php</code> class have an <code>actionFiveMinuteRedirect()</code> method that simply did a permanent <a href="http://buildwithcraft.com/classreference/controllers/BaseController#redirect-detail" rel="nofollow">redirect</a>:</p>

<pre><code>`$this-&gt;redirect('5minutes', true, 301);`
</code></pre>

CC BY-SA 3.0
2015-07-10T20:49:54.330Z
He did mention that it's in his plugin. If he intends for his plugin to be portable, then .htaccess isn't going to solve his problem. But, if it's a one-off business logic plugin, then I fully agree that .htaccess is the way to go.
Lindsey D
CC BY-SA 3.0
2015-07-11T03:08:35.390Z
Doh! Totally missed the plugin part.  Will update my answer.
Brad Bell
CC BY-SA 3.0
2015-07-10T20:44:29.797Z
2015-07-11T03:22:19.327Z
2015-07-11T03:22:19.327Z
Brad Bell
<p>I have a "/5minutes" url in routes.php and people keep typing in "fiveminutes". Is there a way to call a 301 redirect directly in routes.php or would I need to set up an action in my plugin (or alternatively mess with server settings)?</p>

<plugin-development><url><routes><redirect>
Setting up redirects from routes.php
# Setting up redirects from routes.php

(Asked by: username_0 on 2015-07-10)

I have a "/5minutes" url in routes.php and people keep typing in "fiveminutes". Is there a way to call a 301 redirect directly in routes.php or would I need to set up an action in my plugin (or alternatively mess with server settings)?

**Tags:** plugin-development, url, routes, redirect


---

## 1 answers

### Answer by username_1 on 2015-07-10. Score: 3 | Accepted answer

I'd try and avoid the routes.php route (pun intended).  There isn't any need to get Craft involved in a redirect when your web server (Apache?) can handle it much faster.
If you're using Apache, then adding something like this to your public .htaccess file should do the trick:
RewriteRule ^fiveminutes$ /5minutes [NC,R=301,L]

Update:
Missed the part where you said this was in a plugin.  In that case you'd want to setup something like this in your main plugin's class file:
public function registerCpRoutes()
{
    return array(
        'fiveminutes' => array('action' => 'myPluginController/fiveMinuteRedirect'),
   );
}

Then from your MyPluginController.php class have an actionFiveMinuteRedirect() method that simply did a permanent redirect:
`$this->redirect('5minutes', true, 301);`

> **Comments:**
> **username_2**: He did mention that it's in his plugin. If he intends for his plugin to be portable, then .htaccess isn't going to solve his problem. But, if it's a one-off business logic plugin, then I fully agree that .htaccess is the way to go.  
> **username_1**: Doh! Totally missed the plugin part.  Will update my answer.  

---

