Answers.Body: <p>In Craft 3, you can accomplish this by <a href="https://docs.craftcms.com/v3/extend/updating-plugins.html#routing-hooks" rel="nofollow noreferrer">hooking into the <code>UrlManager::EVENT_REGISTER_SITE_URL_RULES</code> event</a>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-06T14:40:15.023Z
Answers.LastActivityDate: 2019-09-06T14:40:15.023Z
Answers.UserDisplayName: Matt Stein
Answers.Body: <p>Is the <a href="http://buildwithcraft.com/docs/plugins/hooks-reference#registerSiteRoutes"><code>registerSiteRoutes</code> hook</a> what you're looking for?</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-24T15:50:28.770Z
Answers.Text: I think this is exactly what I want :)
Answers.UserDisplayName: Tyler Willingham
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-24T15:44:41.337Z
Answers.LastActivityDate: 2014-07-24T16:04:08.493Z
Answers.LastEditDate: 2014-07-24T16:04:08.493Z
Answers.UserDisplayName: Wes Rice
Body: <p>I don't suspect it's currently possible but  I would be pleasantly surprised to find that it is.</p>
  
  <p>I'm going to use an example from Django because I've seen it used there and a similar implementation would be handy to have in Craft. Annnnd it would be helpful for what we're trying to achieve with my current project.</p>
  
  <p><strong>Example:</strong>
  In Django you have your project-wide urls.py (think of this as routes.php in Craft). Additionally you can have app-specific URLs (an App might be a Blog or a Portfolio). You can define the app-specific paths in the app-specific urls.py file and then you can include those URLs in the project-wide URL file. That might look like this (example from the Django docs):</p>
  
  <pre><code>urlpatterns = [
      # ... snip ...
      url(r'^community/', include('django_website.aggregator.urls')),
      url(r'^contact/', include('django_website.contact.urls')),
      # ... snip ...
  ]
  </code></pre>
  
  <p>So a use-case:</p>
  
  <p>We're developing a REST API and right now all of our routes are defined in routes.php. That's an ok solution, but we have a lot of plugin-specific routes. It would be nice to be able to define a base such as /api/ and pass the rest of the request to a plugin-specific routes file.</p>
  
  <p>An idea of what this might look like:</p>
  
  <pre><code>return array(
      'api'   =&gt; array('pluginRoutes' =&gt; 'apiPluginName'),
  );
  </code></pre>
  
  <p>And then in craft/plugins/apiPluginName/routes.php would be a routes file similar to the project-wide routes.php file in craft/config</p>
  
Tags: <plugin-development><routes><custom>
Title: Can we define routes (non-CP) in plugins?
ThreadText: # Can we define routes (non-CP) in plugins?
  
  (Asked by: username_0 on 2014-07-24)
  
  I don't suspect it's currently possible but I would be pleasantly surprised to find that it is.
  
  I'm going to use an example from Django because I've seen it used there and a similar implementation would be handy to have in Craft. Annnnd it would be helpful for what we're trying to achieve with my current project.
  
  **Example:**
  In Django you have your project-wide urls.py (think of this as routes.php in Craft). Additionally you can have app-specific URLs (an App might be a Blog or a Portfolio). You can define the app-specific paths in the app-specific urls.py file and then you can include those URLs in the project-wide URL file. That might look like this (example from the Django docs):
  
  ```
  urlpatterns = [
      # ... snip ...
      url(r'^community/', include('django_website.aggregator.urls')),
      url(r'^contact/', include('django_website.contact.urls')),
      # ... snip ...
  ]
  
  ```
  
  So a use-case:
  
  We're developing a REST API and right now all of our routes are defined in routes.php. That's an ok solution, but we have a lot of plugin-specific routes. It would be nice to be able to define a base such as /api/ and pass the rest of the request to a plugin-specific routes file.
  
  An idea of what this might look like:
  
  ```
  return array(
      'api'   => array('pluginRoutes' => 'apiPluginName'),
  );
  
  ```
  
  And then in craft/plugins/apiPluginName/routes.php would be a routes file similar to the project-wide routes.php file in craft/config
  
  **Tags:** plugin-development, routes, custom
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2014-07-24. Score: 13 | Accepted answer
  
  Is the [`registerSiteRoutes` hook](http://buildwithcraft.com/docs/plugins/hooks-reference#registerSiteRoutes) what you're looking for?
  
  > **Comments:**
  > **username_0**: I think this is exactly what I want :)  
  
  ---
  
  ### Answer by username_1 on 2019-09-06. Score: 2
  
  In Craft 3, you can accomplish this by [hooking into the `UrlManager::EVENT_REGISTER_SITE_URL_RULES` event](https://docs.craftcms.com/v3/extend/updating-plugins.html#routing-hooks).
  
  
  ---
  
  