Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Can we use inline routes with regular expression?
  • Hello,

    I tried the code below but it didn't work well.. I would like to redirect all the accesses under the folder xxx to the folder yyy.

    'xxx/:any' => function() { Response::redirect('yyy/$1'); }

    Can we set up this sort of redirection using routes file or should we put it in a controller file or somewhere else?

    Thanks,
    Ponto
  • No, it doesn't work like that. $1 is a replacement parameter in the regex, and a closure isn't a replacement string you can use in a regex statement.

    What you can do is:

    'xxx/:any' => function() { $x = Uri::segments(); $x[0] = "yyy"; Response::redirect(implode("/", $x)); }

    Note that it is probably faster to rewrite using your webserver config.
  • Hi Harro Verton,

    Thanks for the comment! Yes that's true we should rewrite url using webserver's config :)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion