Answers.Body: <p>Well I have managed to achieve what I needed, I'm not sure if this is a very good way to do it though.</p>
  
  <p>I've done it by getting the element of the page I needed and passing that to the route along with the template to use. </p>
  
  <p>It all seems to work though.</p>
  
  <pre><code>Event::on(
          UrlManager::class,
          UrlManager::EVENT_REGISTER_SITE_URL_RULES,
          static function (RegisterUrlRulesEvent $event) {
              $element = Craft::$app-&gt;getElements()-&gt;getElementByUri(
                  'site-start-your-quote',
                  Craft::$app-&gt;getSites()-&gt;getCurrentSite()-&gt;id,
                  true);
              $event-&gt;rules['POST start-your-quote'] = 'craft-lp-api-helper/lpapi';
              $event-&gt;rules['GET start-your-quote'] = [
                  'template' =&gt; '_layouts/forms/start-your-quote.twig',
                  'variables' =&gt; [
                      'entry' =&gt; $element,
                  ],
              ];
          }
      );
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-06T12:45:25.683Z
Answers.LastActivityDate: 2020-02-06T12:45:25.683Z
Answers.UserDisplayName: SloganHD
Body: <p>Within a plugin I have written I would like to route POST requests to the plugin controller and GET requests to a single entity created in craft.</p>
  
  <p>When the user POSTs to <a href="http://example.com/start-your-quote" rel="nofollow noreferrer">http://example.com/start-your-quote</a> it should be handled by the plugin controller. When the user GETs <a href="http://example.com/start-your-quote" rel="nofollow noreferrer">http://example.com/start-your-quote</a> it should load the single entity with the slug 'site-start-your-quote'</p>
  
  <p>I have written the following in the hopes of achieving this:-</p>
  
  <pre class="lang-php prettyprint-override"><code> Event::on(
              UrlManager::class,
              UrlManager::EVENT_REGISTER_SITE_URL_RULES,
              static function (RegisterUrlRulesEvent $event) {
                  $event-&gt;rules['POST start-your-quote'] = 'craft-lp-api-helper/lpapi';
                  $event-&gt;rules['GET start-your-quote'] = 'site-start-your-quote';
              }
          );
  </code></pre>
  
  <p>The POST is working as expected, however the GET results in the following error:-</p>
  
  <blockquote>
    <p>Blockquote
    HTTP 404 – Not Found – yii\web\NotFoundHttpException
    Page not found.
    ↵
    Caused by: Invalid Route – yii\base\InvalidRouteException
    Unable to resolve the request "site-start-your-quote".</p>
  </blockquote>
  
  <p>Hopefully I am missing something simple and someone can point me in the righ direction?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-02-05T22:50:51.593Z
Comments.Text: Mmmm first thought is site-start-your-quote isn't a get request?
Comments.UserDisplayName: joomkit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-02-06T07:39:06.463Z
Comments.Text: Thanks @joomkit but going to that slug direct in a browser works fine, it's just from the route rule I'm getting the 404.
Comments.UserDisplayName: SloganHD
Tags: <plugin-development><craft3><routes>
Title: RegisterUrlRulesEvent rule to display site page
ThreadText: # RegisterUrlRulesEvent rule to display site page
  
  (Asked by: username_0 on 2020-02-05)
  
  Within a plugin I have written I would like to route POST requests to the plugin controller and GET requests to a single entity created in craft.
  
  When the user POSTs to <http://example.com/start-your-quote> it should be handled by the plugin controller. When the user GETs <http://example.com/start-your-quote> it should load the single entity with the slug 'site-start-your-quote'
  
  I have written the following in the hopes of achieving this:-
  
  ```php
   Event::on(
              UrlManager::class,
              UrlManager::EVENT_REGISTER_SITE_URL_RULES,
              static function (RegisterUrlRulesEvent $event) {
                  $event->rules['POST start-your-quote'] = 'craft-lp-api-helper/lpapi';
                  $event->rules['GET start-your-quote'] = 'site-start-your-quote';
              }
          );
  
  ```
  
  The POST is working as expected, however the GET results in the following error:-
  
  > Blockquote
  > HTTP 404 – Not Found – yii\web\NotFoundHttpException
  > Page not found.
  > ↵
  > Caused by: Invalid Route – yii\base\InvalidRouteException
  > Unable to resolve the request "site-start-your-quote".
  
  Hopefully I am missing something simple and someone can point me in the righ direction?
  
  **Tags:** plugin-development, craft3, routes
  
  > **Comments:**
  > **username_1**: Mmmm first thought is site-start-your-quote isn't a get request?  
  > **username_0**: Thanks @username_1 but going to that slug direct in a browser works fine, it's just from the route rule I'm getting the 404.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-02-06. Score: 1 | Accepted answer
  
  Well I have managed to achieve what I needed, I'm not sure if this is a very good way to do it though.
  
  I've done it by getting the element of the page I needed and passing that to the route along with the template to use.
  
  It all seems to work though.
  
  ```
  Event::on(
          UrlManager::class,
          UrlManager::EVENT_REGISTER_SITE_URL_RULES,
          static function (RegisterUrlRulesEvent $event) {
              $element = Craft::$app->getElements()->getElementByUri(
                  'site-start-your-quote',
                  Craft::$app->getSites()->getCurrentSite()->id,
                  true);
              $event->rules['POST start-your-quote'] = 'craft-lp-api-helper/lpapi';
              $event->rules['GET start-your-quote'] = [
                  'template' => '_layouts/forms/start-your-quote.twig',
                  'variables' => [
                      'entry' => $element,
                  ],
              ];
          }
      );
  
  ```
  
  
  ---
  
  