Redirecting all requests to one route

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Redirecting all requests to one route

tonystamp
Hey all, i'm wondering if there's a way to redirect all requests to a single route?

I am working on a site and want to upload the work-in-progress page, and have all requests sent to that route that displays that page.

When i tried editing my .htaccess to send all requests to that page it was throwing up a 404, presumably because the request was not going through the framework.
Reply | Threaded
Open this post in threaded view
|

Re: Redirecting all requests to one route

Michael Gooden
Hi Tony,

Create a segment route of '/*', and make sure it is registered last. This
will catch all requests that could not be routed by existing routes.

Cheers,

Michael


On 8 August 2013 00:53, tonystamp <[hidden email]> wrote:

> Hey all, i'm wondering if there's a way to redirect all requests to a
> single
> route?
>
> I am working on a site and want to upload the work-in-progress page, and
> have all requests sent to that route that displays that page.
>
> When i tried editing my .htaccess to send all requests to that page it was
> throwing up a 404, presumably because the request was not going through the
> framework.
>
>
>
> --
> View this message in context:
> http://zend-framework-community.634137.n4.nabble.com/Redirecting-all-requests-to-one-route-tp4660699.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Redirecting all requests to one route

renatomefidf
This post has NOT been accepted by the mailing list yet.
In reply to this post by tonystamp
You can catch all requests at an action plugin.

---------------------------------------------------------
Renato Mendes Figueiredo
(61) 9122-5946 ou (61) 3345-8648


On Wed, Aug 7, 2013 at 7:57 PM, tonystamp [via Zend Framework Community] <[hidden email]> wrote:
Hey all, i'm wondering if there's a way to redirect all requests to a single route?

I am working on a site and want to upload the work-in-progress page, and have all requests sent to that route that displays that page.

When i tried editing my .htaccess to send all requests to that page it was throwing up a 404, presumably because the request was not going through the framework.


If you reply to this email, your message will be added to the discussion below:
http://zend-framework-community.634137.n4.nabble.com/Redirecting-all-requests-to-one-route-tp4660699.html
To unsubscribe from Zend Framework, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Redirecting all requests to one route

richard
In reply to this post by Michael Gooden
I would probably use a simple module to always modify the route match
controller and action. If the module is enabled, the route will be set as
controller / action unless there is no route match in which case it will
404. I started out with some example code then formalised slightly as I
think I may find this useful at times.

<?php
namespace Trueaxiom\Module\SingleRoute;

use Zend\Mvc\MvcEvent;
use Zend\EventManager\EventInterface;
use Zend\ModuleManager\Feature\BootstrapListenerInterface;

/**
 * Modify Route Match to always return controller / action.
 */
class Module
{
    /**
     * @var string
     */
    protected $controller = 'Acl\Controller\Index';

    /**
     * @var string
     */
    protected $action = 'index';

    /**
     * Add Route Listener
     * @param  EventInterface $e
     */
    public function onBootstrap(EventInterface $e)
    {
         $e->getApplication()->getEventManager()->attach('route',
array($this, 'onRoute'), -1000);
    }

    /**
     * Route Listener Callback to Modify Route Match
     * @param  MvcEvent $e
     */
    public function onRoute(MvcEvent $e)
    {
        $rm = $e->getRouteMatch();
        $rm->setParam('controller', $this->controller);
        $rm->setParam('action', $this->action);
    }
}




On Wed, Aug 7, 2013 at 11:56 PM, Michael Gooden <[hidden email]>wrote:

> Hi Tony,
>
> Create a segment route of '/*', and make sure it is registered last. This
> will catch all requests that could not be routed by existing routes.
>
> Cheers,
>
> Michael
>
>
> On 8 August 2013 00:53, tonystamp <[hidden email]> wrote:
>
> > Hey all, i'm wondering if there's a way to redirect all requests to a
> > single
> > route?
> >
> > I am working on a site and want to upload the work-in-progress page, and
> > have all requests sent to that route that displays that page.
> >
> > When i tried editing my .htaccess to send all requests to that page it
> was
> > throwing up a 404, presumably because the request was not going through
> the
> > framework.
> >
> >
> >
> > --
> > View this message in context:
> >
> http://zend-framework-community.634137.n4.nabble.com/Redirecting-all-requests-to-one-route-tp4660699.html
> > Sent from the Zend Framework mailing list archive at Nabble.com.
> >
> > --
> > List: [hidden email]
> > Info: http://framework.zend.com/archives
> > Unsubscribe: [hidden email]
> >
> >
> >
>