ExpressionEngine® 3 User Guide

Legacy Documentation

You are using the documentation for version 3.5.17. Go here for the latest version or check here for your available upgrades to the latest version.

URL Segment Variables

ExpressionEngine provides an easy way for you to access the information in your URL segments. By “segments”, we mean the segments of the URL that appear after your index.php page. For example, this URL has two segments:

products is Segment 1 and shirts is Segment 2.

Up to 9 URL segments can be accessed using the following variables:

{segment_1} {segment_2} {segment_3} {segment_4} {segment_5} {segment_6} {segment_7} {segment_8} {segment_9}

In addition to the numbered segment variables, if your template has a Template Route assigned to it the segment names defined in your route will be available as such:


Segment variables let you dynamically change aspects of your templates based on what appears in the URL.

For example, imagine you use an ExpressionEngine channel to store information about each employee in your company. Each channel entry describes a different person, with the URL Title of the entry being the person’s name. In this scenario you could use a single template to dynamically show each employee’s information based on what is in the URL. Consider this URL:

The Template Groups name is “company” and the Template name is “employees”. Based on the information in the 3rd segment (in this case, “joe”) you can dynamically cause the “employees” template to change for each person. Here’s an example of a channel tag in which the URL title changes based on the 3rd segment:

{exp:channel:entries url_title="{segment_3}"}

Last Segment

The {last_segment} global variable gives you the ability to determine the last segment of your URL when the number of URI segments is unknown.

{if last_segment == 'joe'}     Hey Joe, where you goin' with that? {/if}

Hey {last_segment}, where you goin' with that?