Skip to main content

Hey, Optimizely X users! Don't waste time looking for resources about Optimizely X Web Experimentation. We've got them for you here

Optimizely Knowledge Base

URL Targeting: Choose where your experiment runs

If you're looking to edit your pages in Optimizely X, check out this article.
relevant products:
  • Optimizely X Web Experimentation
  • Optimizely X Web Personalization
  • Optimizely Classic

This article will help you:
  • Choose which URLs the visitor needs to use to determine whether the experiment will run
  • Learn about the different URL match types available in Optimizely: simple, exact, substring, and RegEx
  • Run experiments that make the same change across multiple pages

URL Targeting at a glance

Once you've created your variations in the Editor, you'll tell Optimizely where the experiment should run on your site. Use the match types below to target a specific URL or a group of URLs.

Key tips

  • Use Simple Match when testing a single page
  • Use Exact Match only when adding query parameters or hash parameters to the URL significantly changes how the page displays 
  • Use Substring Match for experiments that change the same element across many pages
  • Use Regular Expressions to target complicated URL structures 

What to watch out for

URL Targeting specifies the pages on which an experiment or campaign should run. You have the ability to target specific URLs or groups of URLs depending on the match type selected.

In Optimizely X, URL Targeting is a property of a Page. You can access it in the following ways:

  • Go to the Implementation page, then the Pages tab.
  • From the campaign creation flow, if you don't have an existing page to add, click Create New Page.

In Optimizely Classic, you can access URL Targeting in the following ways:

  • From the Home page, go to the Experiments tab and select your experiment. Navigate to the right-sidebar and click Edit next to URL Targeting.
  • From the Optimizely Editor, go to Options > URL Targeting

Use URL targeting to determine where experiments run on your site. If you want to control who can see the experiment, you'll want to use audiences.

Want to see this feature in action? Check out our two-minute video on URL Targeting:


Have a question about targeting? Head over to the Optimizely Community to post a discussion and see what others are talking about.

URL Match Types

In the URL Targeting menu, you can enter URL match specifications that tell Optimizely where the experiment should run. 

Each URL match you enter can be one of four types:

  • Simple Match: This is the default match type and is generally useful when testing a single page.
  • Exact Match: This match type should be used only when adding query parameters or hash parameters to the URL will significantly change how the page displays for visitors. (If you want to target visitors who are using a certain query parameter, use an Audience Condition instead.)
  • Substring Match: This will match specific strings of texts within a URL. It's useful for experiments that change the same element sitewide, or across many pages.
  • Regular Expressions: These can be used to target complicated URL structures that aren't easily captured by the other URL match types. If this doesn't work for you, you may want to use custom tags on the pages you intend to target.

It is worth noting that Regular Expressions are case-sensitive, while Simple, Substring and Exact Matches are not case-sensitive.

We describe the match types in more depth below.

Simple Match

Simple match is the default URL match type, and it's ideal for running experiments on single pages. It will run when visitors land on a URL, even if it has the following variations:

Simple match will ignore these changes and run your experiment on the page, because those modifications usually don't change the way your page displays.

To use simple match, just enter the full URL (the absolute URL, not a relative URL like /products/general.html) of the page you want to target. Here's an example of the common variants that will pass a simple match:

URL Targeting copy.gif

The above examples match because they run on the same page as the original URL. Even adding query (?) or hash (#) parameters doesn't generally change the page.

What won't match the original? Some examples of changes that simple match WON'T ignore are:

  • Changes in subdomain (aside from www)
  • Adding .html or other extensions
  • Adding or changing subdirectories

See below for some examples:

In the above example, these would not match the original URL because they are not the same page. Specifically:

Example: User account page with many dynamic/unique query string values

You want to run an experiment on a “My Account” page for all of your customers. However, every account URL includes query parameters unique to a particular visitor’s information. A sample Account URL would be:

Setting it up:

  • Identify which portion of the account page URL is static and which portion is dynamic.

  • In this case, the URL to the left of the “?” will always be the same, while the parameters to the right of the “?” will be unique to each user.

  • In the URL targeting, select “Simple match” from the dropdown, and add the account URL, excluding all query string parameters. In this case it would

  • A simple match ignores anything to the right of the question mark in the URL (ie. all query string parameters). In the example above, ?account_id=1234&location=san_francisco would be ignored, which is what we want since these will be dynamic.

  • This setup ensures that your experiment will run on all account pages, regardless of the unique customer who is viewing the page.

Example: Visitors who land on only two of many landing pages

You have around 10 landing pages live at any one time, and you want to run an A/B test on just two of these pages. You know there will always be unique utm/query parameters added to the URL from paid search traffic, but you want the experiment to run regardless of which campaign the visitor came from.

Setting it up:

  • Identify what the two specific URLs look like and how they differ from other landing page URLs on your domain.

  • In the URL targeting, select “Simple match” from the dropdown and add the URL of the first landing page.

  • Click the green “+” icon and add the URL of the second landing page as a “Simple match.”

  • A simple match ignores anything to the right of the question mark in the URL (ie. all query string parameters). This set-up ensures the experiment will only run if the visitor lands on the first landing page URL or the second landing page URL.

You may also find simple match handy to exclude certain URLs from a substring match that targets many pages at once (see below for more on substring match).

In the above example, the examples including are excluded because the targeting is set to exclude that URL as a simple match.

Exact Match

Exact match URLs will run an experiment only when users load the exact URL.

Like simple match, exact match will ignore trailing slashes, http/https protocols, and www. Also like simple match, exact match will not ignore subdirectories, extensions, or changes in subdomains ( vs or See our simple match description above for more information.

Unlike simple match, exact match will not ignore changes to query or hash parameters.

Enter a full URL when using exact match (the absolute URL, not a relative URL like /products/general.html).

In this example, www.example.com would be included because Exact match accepts these common variations. The following would be excluded:

If you specify a particular query or hash parameter, exact match will allow only that exact parameter into the experiment.

Exact match may come in handy when excluding specific query or hash parameters from a simple match.

Substring Match

Substring match runs an experiment when the URL contains a set of characters that you specify. This set of characters is referred to as a substring, and can be present anywhere in the URL. 

For example, if you wanted to target an element on all product pages, look for a part of your URL that is consistent across all of those pages. If the substring '/products' is in every product page, run a substring match on '/products'. 

Substring match ignores trailing slashes and http/https protocols. But it doesn't ignore subdomains (including 'www'), subdirectories, extensions, or changes to query/hash parameters.

Unlike simple and exact match, substring match doesn't need a full URL to match. You can substring match on a word, a query parameter, a subdirectory, or any other substring that might appear somewhere in the URL.

This makes substring match ideal for targeting entire categories of pages, or targeting your entire site (for example, to make a change to your global navigation menu).

Here's how a substring match will target the experiment when you include www (or another subdomain):

In the above example, only the URLs that include the string are included.

But notice that when you remove the subdomain or 'www', it will target any page on your domain where the snippet is implemented.

You can target an entire category of pages by including the directory that appears in their URL:

In the above example, all strings that include the stringhatsare included.

You can also target a certain parameter anywhere it appears:

In the above example, all the strings that include the string utm_campaign=springpromo are included.

Example: Testing on categories of pages

You want to run an experiment on all of your product detail pages, but you want to be sure that your changes do not also show up on other pages of the site. You know that all the product page URLs look similar (an example of one might be:, where everything after “product” is dynamic).

Setting it up:

  • Identify a common URL structure for all of your product pages that is unique to those pages.

  • In the URL targeting section, choose substring match and enter the portion of the URL that is guaranteed to be the same across the desired set of pages.

  • For example, use a substring match for

  • This will ensure that the experiment will run on any URL that has the string present in the full URL. Any values can be added before of after this string and the match will still apply.

  • If your product pages do not have a common URL structure, you may need to use custom tags instead of a substring match.

Example: Run sitewide except for a certain sub-set of pages

You want to run a sitewide navigation bar change across all the main pages on your site. However, there is a sub-set of “news” pages that do not follow your site’s standard layout, so you want to exclude these page from the experiment.

You know that the “news” pages all have a URL that begins with The dynamic topic and article name are appended after “news/”.

For example, a full URL would be:

Setting it up:

  • Start with the bigger group of pages that you do want to include in the experiment. In this case, you would set a substring match to to ensure the experiment runs site-wide.

  • Now, you will want to identify a common URL structure for all of the pages that should be excluded from the test.

  • In the URL targeting section, choose “Exclude URLs,” and select “Substring match” from the dropdown menu. Enter the portion of the URL that is guaranteed to be the same across the specific set of pages.

  • In the example above, a substring match works.

  • The experiment will run on page on your domain that have the substring, but NOT any pages that have the string

  • When using “Exclude” in URL targeting, both positive and negative conditions must be met. In other words, the visitor must land on a page that matches the included condition but does not match the excluded condition.

Regular Expression Match

Expert users can use regular expressions ("regex") to specify a set of pages on which an experiment should run.

For example, to target all pages on your site where the snippet is implemented, use a Regular Expression Match and enter .* as your match condition.

While it's impossible to cover all of the different possibilities this allows for here, we'll provide a small sample.

Let's say you want to target your experiment to pages in your /products/shoes, /products/hats, and /products/shirts sections but no others. You might write a regular expression that looks like this: /products/(shoes|hats|shirts).*

Regex matches are evaluated using JavaScript's built-in regular RegExp module. Your expression is matched against the full page URL, and will be evaluated as a Substring match up until an escaped character in your expression. Alternatively you could write the RegEx in the above example fully in RegEx:\/products\/shoes|hats|shirts.*

Your expression does not need to match the full URL in order to trigger your experiment using Optimizely. For example, the regular expression 'x=y' will match all of the following pages:

If you're trying to target a series of pages that can't be included neatly in a substring match or RegEx, consider adding Custom Tags to the pages you want to target, and targeting visitors who land on a page containing that tag. Note that Custom Tags are an Audience condition, not a URL Targeting condition, but they can be used to accomplish the same purpose.

URL Match Validator: Double-check your targeting

To check your targeting conditions and ensure that your experiment will run on the expected pages, you can use the URL Match Validator.

The URL Match Validator lets you enter sample URLs and tells you whether they match the URL Targeting conditions. A match signifies that the experiment will run. A non-match means the experiment won't run.

The URL match validator allows you to quickly confirm whether a URL Targeting Condition or Pageview Goal will correctly target the URLs you intend. Use the + signs to add as many sample URLs as you want. Try checking for URLs that you do, and don't, expect to match in your experiment.

Editing elements that appear sitewide or on multiple pages

URL Targeting can be used to A/B test a single element that appears on multiple pages, such as a navigation bar or a footer.

Want to see this in action? Check out our one-minute video on changing an element on multiple pages:

  1. Optional: Make sure the element(s) has a unique id in your code. This will ensure that regardless of the page layout the correct element will be modified.

  2. Create an experiment on one page that contains the element in question. At this point, you'll use this page as a template, so you don't need to load the other pages that contain this element.

  3. Make necessary modifications to the element.

  4. Click Options > URL Targeting

  5. Update the URL Targeting to include every page that contains the element you modified. Typically, Substring Match does this very well.

  6. Make sure the Optimizely Snippet is on all of those pages, otherwise the experiment will not run.

By doing this you guarantee that visitors continue to see the same variation of the element in question throughout the website. See below for more use cases that use URL Targeting for this purpose.


Adding multiple pages to an experiment will not affect your unique visitor count, as we measure unique visitors, not page views.

URL Targeting is a fundamental of AB testing, and mastering it will help you run better experiments.