# Creating new Redirect

pro business

# Example

  1. Create new file in /var/www/keitaro/application/redirects/. For example, /var/www/keitaro/application/redirects/custom_redirect.php.

  2. The boilerplate code:

<?php
namespace Redirects;

use Traffic\Actions\AbstractAction;

class custom_redirect extends AbstractAction
{
    protected $_name = 'CustomRedirect';     // <-- Redirect name
    protected $_weight = 100;                // <-- Redirect weight in action dropdown

    public function getType()
    {
        return self::TYPE_REDIRECT;              // <-- That tells Keitaro that script is a redirect 
    }

    protected function _execute()  
    {
        $url = $this->getActionPayload();
        
        $html = '<html>
        <head>
            <meta http-equiv="REFRESH" content="1; URL=\'' . $url. '\'">
            <script type="text/javascript">window.location = "' . $url . '";</script>
        </head>
        <body>
            The document has moved <a href="' . $url . '">here</a>
        </body>
        </html>';
    
        $this->setContentType('text/html')  // <-- Set 'text/html' as content type 
        $this->setStatus(200);              // <-- Set 200 as HTTP status code
        $this->setContent($html);           // <-- Sets $html as output 
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

# Available methods

See PHP interface of AbstractAction.