# Quickest and least expensive way to retrieve URL segment

**URL:** <https://www.ruby-forum.com/t/quickest-and-least-expensive-way-to-retrieve-url-segment/135363>\
**Category:** Radiant CMS\
**Created:** [April 21, 2008, 4:20pm UTC](https://www.ruby-forum.com/t/quickest-and-least-expensive-way-to-retrieve-url-segment/135363 "2008-04-21T16:20:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![orange](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/65b543/32.png) [@orange](https://www.ruby-forum.com/u/orange)\
**Post date:** [April 21, 2008, 4:20pm UTC](https://www.ruby-forum.com/t/quickest-and-least-expensive-way-to-retrieve-url-segment/135363/1 "2008-04-21T16:20:14Z")

</div>

I would like to check a url segment (in this case whether the site is  
/en/ or /zh/) so I can display content based on language.

In Radiant what is the quickest and least expensive way to do this?

Thanks!

---

<div class="post-metadata">

**Author:** ![orange](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/65b543/32.png) [@orange](https://www.ruby-forum.com/u/orange)\
**Post date:** [April 21, 2008, 4:24pm UTC](https://www.ruby-forum.com/t/quickest-and-least-expensive-way-to-retrieve-url-segment/135363/2 "2008-04-21T16:24:27Z")

</div>

The \<r:if\_url\> and \<r:unless\_url\> tags probably provide what you need.  
Give the tags a ‘matches’ attribute that contains a regular expression.  
Here’s an example:

\<r:if\_url matches="^/en/"\>\<r:content part=“body\_en” /\>\</r:if\_url\>

That would output the “body\_en” part if the beginning of the URL matches  
/en/.

Sean

---

<div class="post-metadata">

**Author:** ![orange](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/65b543/32.png) [@orange](https://www.ruby-forum.com/u/orange)\
**Post date:** [April 21, 2008, 4:30pm UTC](https://www.ruby-forum.com/t/quickest-and-least-expensive-way-to-retrieve-url-segment/135363/3 "2008-04-21T16:30:34Z")

</div>

Sean C. wrote:

> The \<r:if\_url\> and \<r:unless\_url\> tags probably provide what you need.  
> Give the tags a ‘matches’ attribute that contains a regular expression.  
> Here’s an example:
> 
> \<r:if\_url matches="^/en/"\>\<r:content part=“body\_en” /\>\</r:if\_url\>
> 
> That would output the “body\_en” part if the beginning of the URL matches  
> /en/.
> 
> Sean

Doh. That was sitting right in front of my face. Thanks for the quick  
reply, Sean!

-R
