Answers.Body: <p>If it's just a simple redirect, it'll be quicker to do it in .htaccess and not invoke PHP/Craft at all.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-06T15:49:26.600Z
Answers.Text: Hey Brad, is this also how you do it with the structure on buildwithcraft.com → Documentation → Installing and Updating?
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-06T15:53:28.090Z
Answers.Text: No it's not, just checked the urls in the code. :D
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-06T15:42:57.650Z
Answers.LastActivityDate: 2014-10-06T15:42:57.650Z
Answers.UserDisplayName: Brad Bell
Answers.Body: <p>We had a pretty similar question already: <a href="https://craftcms.stackexchange.com/q/1488/125">"Setting up redirects via Craft routes?"</a>. </p>
  
  <p>Here's how you could change the code to exchange the parent entry with its first child conditionally. Additionally you can also add a <a href="http://buildwithcraft.com/docs/templating/redirect" rel="nofollow noreferrer"><code>redirect</code></a> to that child page, in case someone edits the url.</p>
  
  <pre><code>{% set linkToChildEntries = ['exhibitors', 'anotherparent'] %}
  
  &lt;ul&gt;
      {% nav page in pages %}
          &lt;li&gt;
  
              {% if page.slug in linkToChildEntries and page.getChildren()|length %}
                  &lt;a href="{{ page.getChildren().first().url }}"&gt;{{ page.title }}&lt;/a&gt;
              {% else %}
                  &lt;a href="{{ page.url }}"&gt;{{ page.title }}&lt;/a&gt;
              {% endif %}
  
              {% ifchildren %}
                  &lt;ul&gt;
                      {% children %}
                  &lt;/ul&gt;
              {% endifchildren %}
  
          &lt;/li&gt;
      {% endnav %}
  &lt;/ul&gt;
  </code></pre>
  
  <p>Of course you can also make this client editable by adding a field to the parent's entry type you then check for instead of managing the to be treated parent entires in the template code.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-06T15:50:55.990Z
Answers.LastActivityDate: 2014-10-06T15:56:12.183Z
Answers.LastEditDate: 2017-04-13T12:51:00.253Z
Answers.UserDisplayName: carlcs
Answers.Body: <p>I don't have any of the code to hand so I'll have to check it later, but I had a similar need and wanted something I could switch on and off across multiple entries, so I went with a <a href="http://buildwithcraft.com/docs/lightswitch-fields" rel="nofollow">lightswitch field</a> and the following code in the template:</p>
  
  <pre><code>{% if entry.firstChildRedirect %}
      {% if entry.children|length %}
          {% redirect entry.children.first.uri %}
      {% endif %}
  {% endif %}
  </code></pre>
  
  <p>I've also got a <a href="http://buildwithcraft.com/docs/plugins/variables" rel="nofollow">function in a variable</a> that when given an entry, either returns that entry, or it's first child, using similar logic.</p>
  
  <pre><code>&lt;?php
  namespace Craft;
  
  class YourPluginVariable
  {
      public function entryOrRedirected(EntryModel $entry)
      {
          if($entry-&gt;firstChildRedirect)
          {
              $child = $entry-&gt;children-&gt;first();
  
              if($child) return $child;
          }
  
          return $entry;
      }
  }
  </code></pre>
  
  <p>Which can be used in your templates:</p>
  
  <pre><code>{{ craft.yourPlugin.entryOrRedirected(entry).getLink }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-06T16:14:23.787Z
Answers.LastActivityDate: 2014-10-06T16:14:23.787Z
Answers.UserDisplayName: Mike Pepper
Body: <p>Client has created /exhibitors but wishes it to point to /exhibitors/partners</p>
  
  <p>Can that be done using routes or should we be looking at htaccess rules?</p>
  
Tags: <structure><routes><routing><htaccess>
Title: redirect on a Structure
ThreadText: # redirect on a Structure
  
  (Asked by: username_0 on 2014-10-06)
  
  Client has created /exhibitors but wishes it to point to /exhibitors/partners
  
  Can that be done using routes or should we be looking at htaccess rules?
  
  **Tags:** structure, routes, routing, htaccess
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2014-10-06. Score: 3 | Accepted answer
  
  If it's just a simple redirect, it'll be quicker to do it in .htaccess and not invoke PHP/Craft at all.
  
  > **Comments:**
  > **username_2**: Hey username_1, is this also how you do it with the structure on buildwithcraft.com → Documentation → Installing and Updating?  
  > **username_2**: No it's not, just checked the urls in the code. :D  
  
  ---
  
  ### Answer by username_2 on 2014-10-06. Score: 2
  
  We had a pretty similar question already: ["Setting up redirects via Craft routes?"](https://craftcms.stackexchange.com/q/1488/125).
  
  Here's how you could change the code to exchange the parent entry with its first child conditionally. Additionally you can also add a [`redirect`](http://buildwithcraft.com/docs/templating/redirect) to that child page, in case someone edits the url.
  
  ```
  {% set linkToChildEntries = ['exhibitors', 'anotherparent'] %}
  
  <ul>
      {% nav page in pages %}
          <li>
  
              {% if page.slug in linkToChildEntries and page.getChildren()|length %}
                  <a href="{{ page.getChildren().first().url }}">{{ page.title }}</a>
              {% else %}
                  <a href="{{ page.url }}">{{ page.title }}</a>
              {% endif %}
  
              {% ifchildren %}
                  <ul>
                      {% children %}
                  </ul>
              {% endifchildren %}
  
          </li>
      {% endnav %}
  </ul>
  
  ```
  
  Of course you can also make this client editable by adding a field to the parent's entry type you then check for instead of managing the to be treated parent entires in the template code.
  
  
  ---
  
  ### Answer by username_3 on 2014-10-06. Score: 1
  
  I don't have any of the code to hand so I'll have to check it later, but I had a similar need and wanted something I could switch on and off across multiple entries, so I went with a [lightswitch field](http://buildwithcraft.com/docs/lightswitch-fields) and the following code in the template:
  
  ```
  {% if entry.firstChildRedirect %}
      {% if entry.children|length %}
          {% redirect entry.children.first.uri %}
      {% endif %}
  {% endif %}
  
  ```
  
  I've also got a [function in a variable](http://buildwithcraft.com/docs/plugins/variables) that when given an entry, either returns that entry, or it's first child, using similar logic.
  
  ```
  <?php
  namespace Craft;
  
  class YourPluginVariable
  {
      public function entryOrRedirected(EntryModel $entry)
      {
          if($entry->firstChildRedirect)
          {
              $child = $entry->children->first();
  
              if($child) return $child;
          }
  
          return $entry;
      }
  }
  
  ```
  
  Which can be used in your templates:
  
  ```
  {{ craft.yourPlugin.entryOrRedirected(entry).getLink }}
  
  ```
  
  
  ---
  
  