Answers.Body: <p>Assigning the current entry is not the best approach, as this will mean the same page is served for <code>/skills</code> and <code>/skills/technology</code> - this is bad for SEO. Instead, you can redirect with the <a href="https://craftcms.com/docs/3.x/dev/tags.html#redirect" rel="nofollow noreferrer"><code>redirect</code> tag</a>:</p>
  <pre class="lang-twig prettyprint-override"><code>{% redirect '/skills/technology/' 301 %}
  </code></pre>
  <p>Comparing with the full URL is error-prone - what if the URL or the <code>skills</code> slug change? Instead, you want to identify you're on the parent page in a more robust way. How to do that depends on what template the <code>/skills</code> path is routed to.</p>
  <ul>
  <li>If it's an entry of it's own, I would move the redirect logic out of the template and into the entry content, so editors can change the 'main' skill entry to redirect to. Create an entries field limited to one allowed entry and use this as the redirect target.</li>
  <li>If it's a custom route, you can route it to a different template from the main <code>skills</code> template and redirect to the technology page instead. You can also use a field in a global set to allow editors to change the main redirect this way.</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-21T11:33:12.897Z
Answers.Text: This is really great - thanks for the info. As a follow up question (as I am routing the channel as an entry of its own). What do you think is the best option for getting the channels address without the slug i.e. if channel address variable with no slug then redirect? Would you suggest using the redirect entry variables url (using .url) and then splitting the string using '/' as a separator - or is there a dedicated craft call that identifies if there is a slug on this page? Thanks again. W
Answers.UserDisplayName: Wally
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-21T11:58:20.400Z
Answers.Text: @Wally Check the [craft\web\Request](https://docs.craftcms.com/api/v3/craft-web-request.html) class, it has a lot of useful methods to get parts of the URL. But I wouldn't rely on the path at all for redirect logic. Instead, make the condition something that editors can edit. For example, make the entries field optional and only redirect if an entry is selected there. Or only redirect if the entry `level` is 1. Or something along those lines.
Answers.UserDisplayName: MoritzLost
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-21T12:03:49.523Z
Answers.Text: Amazing thanks for the info and really appreciate the quick reply - legend!
Answers.UserDisplayName: Wally
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-20T19:19:24.453Z
Answers.LastActivityDate: 2021-12-20T19:19:24.453Z
Answers.UserDisplayName: MoritzLost
Body: <p>I was wondering if there was a way to set a channels page as the default page to load if there is no slug address i.e. I want the below web address to default to a skills page</p>
  <pre><code>myWebsite.com/skills
  </code></pre>
  <p>Should direct to</p>
  <pre><code>myWebsite.com/skills/Technology
  </code></pre>
  <p>My solution (but I think there is a better way?)</p>
  <p>I cheeped out and set the page entry to the page I want to be the default page if the URL meets the requirement:</p>
  <pre><code>{% set currentPage = craft.request.url %}
  
    {% if currentPage == 'https://exampleWebsite.com/skills' %}
      {% set entry = craft.entries.section('skills').slug('technology').one() %}
    {% endif %}
  </code></pre>
  <p>Any suggestions here would be great!</p>
  <p>Thanks - W</p>
  
Tags: <craft3><routing><channels>
Title: Set a default Channel page if no slug is provided in the URL
ThreadText: # Set a default Channel page if no slug is provided in the URL
  
  (Asked by: username_0 on 2021-12-20)
  
  I was wondering if there was a way to set a channels page as the default page to load if there is no slug address i.e. I want the below web address to default to a skills page
  
  ```
  myWebsite.com/skills
  
  ```
  
  Should direct to
  
  ```
  myWebsite.com/skills/Technology
  
  ```
  
  My solution (but I think there is a better way?)
  
  I cheeped out and set the page entry to the page I want to be the default page if the URL meets the requirement:
  
  ```
  {% set currentPage = craft.request.url %}
  
    {% if currentPage == 'https://exampleWebsite.com/skills' %}
      {% set entry = craft.entries.section('skills').slug('technology').one() %}
    {% endif %}
  
  ```
  
  Any suggestions here would be great!
  
  Thanks - W
  
  **Tags:** craft3, routing, channels
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-12-20. Score: 2 | Accepted answer
  
  Assigning the current entry is not the best approach, as this will mean the same page is served for `/skills` and `/skills/technology` - this is bad for SEO. Instead, you can redirect with the [`redirect` tag](https://craftcms.com/docs/3.x/dev/tags.html#redirect):
  
  ```twig
  {% redirect '/skills/technology/' 301 %}
  
  ```
  
  Comparing with the full URL is error-prone - what if the URL or the `skills` slug change? Instead, you want to identify you're on the parent page in a more robust way. How to do that depends on what template the `/skills` path is routed to.
  
  * If it's an entry of it's own, I would move the redirect logic out of the template and into the entry content, so editors can change the 'main' skill entry to redirect to. Create an entries field limited to one allowed entry and use this as the redirect target.
  * If it's a custom route, you can route it to a different template from the main `skills` template and redirect to the technology page instead. You can also use a field in a global set to allow editors to change the main redirect this way.
  
  > **Comments:**
  > **username_0**: This is really great - thanks for the info. As a follow up question (as I am routing the channel as an entry of its own). What do you think is the best option for getting the channels address without the slug i.e. if channel address variable with no slug then redirect? Would you suggest using the redirect entry variables url (using .url) and then splitting the string using '/' as a separator - or is there a dedicated craft call that identifies if there is a slug on this page? Thanks again. W  
  > **username_1**: @username_0 Check the [craft\web\Request](https://docs.craftcms.com/api/v3/craft-web-request.html) class, it has a lot of useful methods to get parts of the URL. But I wouldn't rely on the path at all for redirect logic. Instead, make the condition something that editors can edit. For example, make the entries field optional and only redirect if an entry is selected there. Or only redirect if the entry `level` is 1. Or something along those lines.  
  > **username_0**: Amazing thanks for the info and really appreciate the quick reply - legend!  
  
  ---
  
  