Answers.Body: <p>You can use the <a href="https://www.yiiframework.com/doc/guide/2.0/en/runtime-routing#catchall-route" rel="nofollow noreferrer">catch all route </a></p>
  
  <pre><code>'catchAll' =&gt; ['site/offline'],
  </code></pre>
  
  <p>For yii1 you can also do </p>
  
  <pre><code>'&lt;url:(.*)&gt;' =&gt; 'controller/action'
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-09T14:28:09.393Z
Answers.Text: Neither of those is having any effect. :(
Answers.UserDisplayName: foamcow
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-09T14:30:49.230Z
Answers.Text: Do you want to route everything or only the routes it doesn't find?
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-09T14:41:58.683Z
Answers.Text: Everything. I need it to work similar to the offline system. But be able to activate it separately. Maybe it could just 302 every request to another template?
Answers.UserDisplayName: foamcow
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-09T14:44:28.277Z
Answers.Text: If I remember correctly in Craft 2 you can't control the default entry routes in your plugins so they'll be routed first no matter what. Thus you can just handle the request in your plugins init function and send the response there
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-09T14:47:48.663Z
Answers.Text: That looks like it might do the trick
Answers.UserDisplayName: foamcow
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-09T14:57:24.300Z
Answers.Text: So close! That will catch all the request... but now I can't render the template from within the init method using craft()->renderTemplate()
Answers.UserDisplayName: foamcow
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-09T15:00:59.867Z
Answers.Text: Of course you can render templates in your init method. What should prevent you?
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-09T15:06:25.897Z
Answers.Text: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/85546/discussion-between-foamcow-and-robin-schambach).
Answers.UserDisplayName: foamcow
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-09T14:13:58.717Z
Answers.LastActivityDate: 2018-11-09T14:13:58.717Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I’m trying to use a plugin to set up a site route that will direct every page request to a special template.</p>
  
  <p>This is what I’ve set up in my plugin file.</p>
  
  <pre><code>public function registerSiteRoutes()
      {
          return array(
              '*' =&gt; 'special/index',
          );
      }
  </code></pre>
  
  <p>Using the above doesn’t seem to do anything. If I replace * with a word, then try to visit that URL I get something different but not my template.
  would love it if someone could put me right here</p>
  
  <p>UPDATE
  If I change tact a bit and route to a controller using a specific url then I can see it gets there</p>
  
  <pre><code>public function registerSiteRoutes()
      {
          return array(
              'beer' =&gt; array('action'=&gt;'beer/index'),
          );
      }
  </code></pre>
  
  <p>But I can't figure out how to catch <em>all</em> requests  using <code>*</code> doesn't appear to do anything</p>
  
  <p>UPDATE
  @robin helped me out massively here with some more info outside the comments.</p>
  
  <p>Basically  in Craft 2 the plugin routes get called first no matter what. So I can hijack the init method to load my special template</p>
  
  <p>UPDATE 2 
  I made this into a Craft 2 plugin. 
  <a href="https://github.com/moresoda/craft-emergency-mode" rel="nofollow noreferrer">https://github.com/moresoda/craft-emergency-mode</a></p>
  
  <p>Craft 3 plugin coming soon.</p>
  
Tags: <plugin-development><routes><craft2>
Title: Set a route for all requests within a plugin
ThreadText: # Set a route for all requests within a plugin
  
  (Asked by: username_0 on 2018-11-09)
  
  I’m trying to use a plugin to set up a site route that will direct every page request to a special template.
  
  This is what I’ve set up in my plugin file.
  
  ```
  public function registerSiteRoutes()
      {
          return array(
              '*' => 'special/index',
          );
      }
  
  ```
  
  Using the above doesn’t seem to do anything. If I replace \* with a word, then try to visit that URL I get something different but not my template.
  would love it if someone could put me right here
  
  UPDATE
  If I change tact a bit and route to a controller using a specific url then I can see it gets there
  
  ```
  public function registerSiteRoutes()
      {
          return array(
              'beer' => array('action'=>'beer/index'),
          );
      }
  
  ```
  
  But I can't figure out how to catch *all* requests using `*` doesn't appear to do anything
  
  UPDATE
  @username_1 helped me out massively here with some more info outside the comments.
  
  Basically in Craft 2 the plugin routes get called first no matter what. So I can hijack the init method to load my special template
  
  UPDATE 2
  I made this into a Craft 2 plugin.
  <https://github.com/moresoda/craft-emergency-mode>
  
  Craft 3 plugin coming soon.
  
  **Tags:** plugin-development, routes, craft2
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-11-09. Score: 1 | Accepted answer
  
  You can use the [catch all route](https://www.yiiframework.com/doc/guide/2.0/en/runtime-routing#catchall-route)
  
  ```
  'catchAll' => ['site/offline'],
  
  ```
  
  For yii1 you can also do
  
  ```
  '<url:(.*)>' => 'controller/action'
  
  ```
  
  > **Comments:**
  > **username_0**: Neither of those is having any effect. :(  
  > **username_1**: Do you want to route everything or only the routes it doesn't find?  
  > **username_0**: Everything. I need it to work similar to the offline system. But be able to activate it separately. Maybe it could just 302 every request to another template?  
  > **username_1**: If I remember correctly in Craft 2 you can't control the default entry routes in your plugins so they'll be routed first no matter what. Thus you can just handle the request in your plugins init function and send the response there  
  > **username_0**: That looks like it might do the trick  
  > **username_0**: So close! That will catch all the request... but now I can't render the template from within the init method using craft()->renderTemplate()  
  > **username_1**: Of course you can render templates in your init method. What should prevent you?  
  > **username_0**: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/85546/discussion-between-username_0-and-username_1-username_1).  
  
  ---
  
  