<p>You can set the URL format to something like this and it should work:</p>

<pre><code>{% if object.type == "image" %}image/{customFieldHandle}{% elseif object.type == "articles" %}articles/{slug}{% endif %}
</code></pre>

CC BY-SA 3.0
2014-09-22T01:42:16.023Z
Nice! Would you mind marking it as the answer?
Brad Bell
CC BY-SA 3.0
2014-09-22T03:04:42.973Z
duh, always forget that.. marked ;)
rey
CC BY-SA 3.0
2014-09-22T00:37:21.250Z
2014-09-22T00:37:21.250Z
Brad Bell
<p>You can't create a separate url format for each type, the url format is defined on a per section basis. But you can use the type as part of the url, if that helps. For instance, you can set the url format to <code>{type.handle}/{slug}</code>. On a recent project I had an <code>article</code> section with entry types like <code>news</code>, <code>video</code>, <code>story</code>, etc. The resulting url structure was <code>/news/slug</code>, <code>/video/slug</code>, <code>/story/slug</code>, etc.</p>

<p>Also, there is nothing stopping you from defining your url structure using routes, and creating the url's based on whatever variables, including entry type. But it would require some more work since you'd have to make sure all your links conform to your defined routes instead of the actual entry urls. </p>

<p>If you provide more info on what you're trying to achieve, maybe I can provide a more concrete solution.</p>

CC BY-SA 3.0
2014-09-20T20:03:40.970Z
Hi Andre, I  just edited my question with more info, thanks!
rey
CC BY-SA 3.0
2014-09-20T19:07:15.540Z
2014-09-20T19:07:15.540Z
André Elvan
<p>Is there any way to set a different url format for each entry type of a section?</p>

<p>I have an entry type "image" on which I will be using the <a href="https://github.com/sjelfull/Craft-Randomm" rel="nofollow">Randomm</a> plugin by Fred Carlsen to generate random strings for the URLs. Something like mysite.com/image/324739483. So I have to set the URL format to image/{customFieldHandle}.</p>

<p>But I also have an entry type "articles" and I'd like to add the actual article name in the URL, like mysite.com/articles/some-article-name.</p>

<url><entry-type>
How to set a different URL format for each entry type of a section?
# How to set a different URL format for each entry type of a section?

(Asked by: username_0 on 2014-09-20)

Is there any way to set a different url format for each entry type of a section?

I have an entry type "image" on which I will be using the [Randomm](https://github.com/sjelfull/Craft-Randomm) plugin by Fred Carlsen to generate random strings for the URLs. Something like mysite.com/image/324739483. So I have to set the URL format to image/{customFieldHandle}.

But I also have an entry type "articles" and I'd like to add the actual article name in the URL, like mysite.com/articles/some-article-name.

**Tags:** url, entry-type

---

## 2 answers

### Answer by username_1 on 2014-09-22. Score: 3 | Accepted answer

You can set the URL format to something like this and it should work:
{% if object.type == "image" %}image/{customFieldHandle}{% elseif object.type == "articles" %}articles/{slug}{% endif %}

> **Comments:**
> **username_1**: Nice! Would you mind marking it as the answer?  
> **username_0**: duh, always forget that.. marked ;)  

---

### Answer by username_2 on 2014-09-20. Score: 2

You can't create a separate url format for each type, the url format is defined on a per section basis. But you can use the type as part of the url, if that helps. For instance, you can set the url format to `{type.handle}/{slug}`. On a recent project I had an `article` section with entry types like `news`, `video`, `story`, etc. The resulting url structure was `/news/slug`, `/video/slug`, `/story/slug`, etc.

Also, there is nothing stopping you from defining your url structure using routes, and creating the url's based on whatever variables, including entry type. But it would require some more work since you'd have to make sure all your links conform to your defined routes instead of the actual entry urls.

If you provide more info on what you're trying to achieve, maybe I can provide a more concrete solution.

> **Comments:**
> **username_0**: Hi Andre, I  just edited my question with more info, thanks!  

---

