- Choose which URLs a visitor needs to use to determine whether a Page should activate on.
- Use the URL match types available in Optimizely Web Experimentation: simple, exact, substring, and regular expression (RegEx)
URL Targeting at a glance
Use the match types described here to target a specific URL or a group of URLs to activate Pages.
- 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 one element across multiple pages or your entire site
- Use regular expression to target complicated URL structures
What to watch out for
Make sure the Optimizely Web Experimentation snippet is implemented on all pages you target
Here is where to find URL targeting:
From the Optimizely App, select Implementation > Pages, then click the ... icon and select Settings
From the Experiment/Campaign Overview page, select Targeting, click the Actions menu and select View
Use URL targeting to determine where Pages should run. Pages will need to be added to your campaign or experiment for targeting. You can read more about Pages here.
Here is how to use URL targeting to edit a sitewide element like a button in the navigation bar or a CTA in the footer.
You can also learn how to build an experiment in our knowledge guide.
URL match types
In the URL Targeting menu, you can enter URL match specifications that tell Optimizely Web Experimentation where the experiment or Page should run.
Each URL match you enter can be one of four types:
Simple match: This is the default match type. Simple match ignores query and hash parameters.
Exact match: Use only when adding query parameters or hash parameters to the URL will significantly change how the page displays for visitors. To target visitors who are using a certain query parameter, use an Audience Condition instead of an exact match
Substring match: Use to match specific strings of texts within a URL. It's useful for experiments that change the same element site-wide or on multiple URLs.
Regular expression: Use to target complicated URL structures that aren't easily captured by the other URL match types.
Regular expressions are case-sensitive. Simple, exact, and substring matches are not case-sensitive.
Read on to learn more about each match type.
Simple match is the default URL match type, and it is ideal for activating Pages on a single URL. This match type ignores query and hash parameters. If a visitor is required to have a specific query or hash parameter then you may want to consider using a Substring, Exact, or Regular Expression match. A simple match will run when visitors land on a URL, even if it has these variations:
Adding or changing a query parameter (like
Adding or changing a hash parameter (like
To use simple match, enter the full URL of the page you want to target—the absolute URL, not a relative URL like
/products/general.html. Here are examples of common variants that will pass a simple match:
These examples match because they run on the same page as the original URL. Adding query (?) or hash (#) parameters do not generally change the page.
In the example below, you will notice that atticandbutton.us/ matches even if it does not have a query parameter. This is because Simple Match ignores query and hash parameters even if they are part of the URL that you are using for targeting.
What will not match the original? Examples of changes that simple match will not ignore include:
Changes in subdomain (aside from www).
Adding .html or other extensions.
Adding or changing subdirectories.
Here are some examples that won’t pass a simple match:
These examples will not match the original URL because they are not on the same page:
Example: User account page with many dynamic/unique query string values
You want to run a Page on a “My Account” page for all of your customers. However, every account URL includes query parameters that are unique to a particular user’s information. A sample Account URL would be:
To set it up:
Identify the static and dynamic portions of the account page URL.
In this case, the URL to the left of the “?” is always the same (static), and the parameters to the right of the “?” are unique to each user (dynamic).
In URL Targeting, select Simple match from the dropdown. Add the account URL, excluding all query string parameters (in this case,
A simple match ignores anything to the right of the question mark in the URL (all query string parameters). In this case,
?account_id=1234&location=san_franciscowould be ignored, which is what we want since this is the dynamic portion of the account page URL.
This setup ensures that your Page will run on all account pages, regardless of the unique user who is viewing the page.
Example: Visitors who land on only two of many landing pages
You have about 10 landing pages live at any one time, and you want to run an A/B test on only two of these URLs. You know there will always be unique UTM/query parameters added to the URL from paid search traffic, but you want the Page to activate regardless of which campaign a visitor comes from.
To set it up:
Identify the two specific URLs you want to test and how they differ from other landing page URLs on your domain.
In URL Targeting, select Simple match from the dropdown and add the URL of the first landing page.
Click the “+” icon and add the URL of the second landing page as a Simple match.
Because a simple match ignores anything to the right of the question mark in the URL (all query string parameters), this set-up ensures the Page will activate only if a visitor lands on the first landing page URL or the second landing page URL.
Simple match may also be handy for excluding certain URLs from a substring match that targets many pages at once.
In these examples, those that include
http://www.atticandbutton.com/aboutare excluded because the targeting is set to exclude that URL as a simple match.
Exact match will only match when users load the exact URL.
Like simple match, exact match ignores trailing slashes at the end of your URL, http/https protocols, and www. Also like simple match, exact match doesn’t ignore subdirectories, extensions, or changes in subdomains (
Unlike simple match, exact match does not ignore changes to query or hash parameters.
Enter a full URL when using exact match—the absolute URL, not a relative URL like
These URLs would be excluded:
http://www.atticandbutton.us/cart/, because it is not the same subdirectory.
http://www.atticandbutton.us/?query=true, because it includes a query parameter.
If you specify a query or hash parameter, exact match allows only that exact parameter into the experiment.
Exact match may come in handy when you want to exclude specific query or hash parameters from a simple match.
Substring matches URLs that contains a set of characters that you specify. This set of characters is called a substring and can be present anywhere in the URL. You can access this targeting by selecting "A set of URLs" under Page Type.
For example, if you want to target an element on all product pages, look for a part of your URL that is consistent across all product pages. If the substring '/products' is in every product page, run a substring match on '/products'.
Substring match ignores trailing slashes that appear at the end of your URL and http/https protocols, but it doesn't ignore subdomains (including 'www'), subdirectories, extensions, or changes to query or hash parameters.
Unlike simple and exact match, substring match does not need a full URL to match. You can substring-match on a word, query parameter, subdirectory, or any other substring that might appear somewhere in the URL. This makes substring match ideal for targeting entire categories of pages or your entire site (for example, to make a change to your global navigation menu).
It is an expected behavior to ignore the trailing forward slash in a substring match. For example, a substring match of '/product/' will pass for 'https://domain.com/product/details' and also for 'https://domain.com/products/' URLs.
This functionality has been 'inherited' from our legacy platform and we chose not to change it due to the high number of already existing pages depending on the current behavior.
Here's how a substring match works when you include www (or another subdomain):
In this example, only the URLs that include the string
www.atticandbutton.us are included.
But when you remove the subdomain or 'www', the substring match targets 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 this example, all strings that include the string
accessories are included.
Example: Testing on categories of pages
You want to run an experiment on all 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 product detail page URLs look similar (for example,
http://www.atticandbutton.us/product...cket?p=84673-0, where everything after “product” is dynamic).
To set it up:
Identify a common URL structure for all of your product pages that is unique to those pages.
In URL Targeting, click on the Page Type drop-down and select A set of URLs.
Select Substring match from the Match Type dropdown and enter the portion of the URL that is guaranteed to be the same across the desired set of pages (for example,
This ensures that the Page will run on any URL that has the string
atticandbutton.us/productsin the full URL. The substring match will apply even if values are added before or after this string.
If your product pages do not have a common URL structure, consider using Conditional Activation instead of a substring match.
Example: Run site-wide, except for a certain subset of pages
You want to run a site-wide navigation bar change across all the main pages on your site. However, a subset of “news” pages do not follow your site’s standard layout, so you want to exclude these “news” pages from the experiment.
You know that the “news” pages all have a URL that begins with
http://www.yellowpages.com/news. The dynamic topic and article name are appended after “news/”.
For example, a full URL might be:
To set it up:
From the Optimizely App, select Implementation on the left nav bar and click New Page.
Select the Page Type drop-down from Single URL to A set of URLs.
Start with the bigger group of pages that you want to include in this Page. In this case, set a substring match to
www.atticandbutton.usto ensure the Page activates site-wide.
Identify a common URL structure for all of the pages that should be excluded from your Page.
In URL Targeting, under Exclude URLs, select Substring match from the dropdown menu. Enter the portion of the URL that is guaranteed to be the same across the set of URLs you want to exclude (in this example,
The Page will run on URLs on your domain that have the substring
www.atticandbutton.us, but not URLs that have the string
When using Exclude URLs in URL Targeting, both positive and negative conditions must be met. In other words, to be included in the experiment, a visitor must land on a URL that matches the included condition and 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. You can access this targeting by select "A set of URLs" under Page Type.
It is impossible to cover all the possibilities that regular expressions allow, but we will provide a small sample.
Let us say you want to target your experiment to URLs in your
/products/shirts sections, but no others. You might write a regular expression that looks like this:
Your expression does not need to match the full URL to trigger your experiment using Optimizely. For example, the regular expression 'x=y' will match the following pages:
Example: Targeting a dynamic URL
You want to run a test on a URL that is dynamic for unique visitors. Substring targeting will not match because the dynamic part of the URL is located in inside the URL.
For example, a full URL might be:
In this example, a substring matching
example.com/us/will not work because we also need to target
myAccount.A substring matching
myAccountwill not work because we do not want to accidentally target another region, such as the UK. The solution is to use a RegEx match that allows any characters and number of characters between
Here is the RegEx used in the example:
The URL will match any string between
/myAccount. It will not match on the url,
myAccountbecause the UK is not part of the match.
When we evaluate a URL using the RegEx match type, Optimizely strips the Optimizely query parameters. For example, if you’re trying to create a RegEx to match http://www.example.com, the added Optimizely query parameters might look like this:
The stripped URL we evaluate would be http://www.example.com/?. Optimizely doesn't remove the
/? when stripping the Optimizely query parameters due to inconsistent behavior among browsers.
To match the URL http://www.example.com, you may want to include matching for the trailing
/?. You could use
example\.com\/?\??$ to match with and without the trailing forward slash and question mark and to not match if there’s an actual query parameter in the URL, like a UTM campaign.
Test URL: Double-check your targeting
To check your targeting conditions and ensure that your Page will run on the expected URL, use Test URL, which can be found in the Targeting modal. Test URL tells you whether the sample URLs you enter match the URL Targeting conditions. A match means the Page will run. A non-match means the Page will not activate.
Test URL lets you quickly confirm whether a URL Targeting condition or pageview goal will correctly target the URLs you intend. Click the “+” icons to add as many sample URLs as you want to validate. Try checking for URLs that you do and don't expect to match in your experiment.