COS-General

How do I set up a flexible pattern URL mapping?

Last updated: April 7, 2016

Available For:

Product: HubSpot Marketing
Subscription: Basic, Professional, & Enterprise

Flexible pattern URL mappings allow you to dynamically redirect urls that have a certain url structure, maintaining parts of the original URL in the destination URL. In HubSpot's COS URL Mappings tool, you can define components of the URL that you would like to add to the destination URL.

To create a flexible pattern mapping:
    • Navigate to Content > Content Settings.
    • From the lefthand sidebar, select COS URL Mappings.
    • Click Add a new redirect > Add one redirect.
    • Click on Show advanced options.
    • Check Advanced: Original URL is a flexible pattern URL.
    • Define your Original URL or Path and Your Destination URL or Path using the syntax below.
User-added image

To define a component part of a URL, use a colon : followed by a name for that variable in the origin URL. To add that component to your destination URL add the same name wrapped in {}. Each piece of the URL path between / / must have its own component, if you would like to include it as a variable in the destination URL.

The one exception to this rule is that you can add the entire end of a URL (up until the query string) as a single component using the * symbol followed by a name for the rest of the URL. Any non-component text in the destination URL will not be dynamically replaced. Below are several examples of flexible pattern URL mappings:

Keeping individual components from original URL

If your original URL structure contained a common pattern such as a date that you wanted to include in the destination URL, you could use a flexible pattern mapping.

Example URL: http://example.com/2012/12/30/my-first-post

Original URL: http://example.com/:year/:month/:day/:post-name

Destination URL: http://blog.example.com/{month}/{day}/{year}/{post-name}

After saving this mapping, original example URL would redirect to: http://blog.example.com/12/30/2012/my-first-post


Defining the end of the URL as a component

Sometimes you may want to make the entire end (up until a query string) of a URL one component.

Example URL: http://www.example.com/product-id/22/jet-ski

Original URL path : http://www.example.com/product-id/*rest-of-url

Destination URL: http://info.example.com/products/{rest-of-url}

After saving this mapping, original example URL would redirect to: http://info.example.com/products/22/jet-ski


Using both individual components and the rest of the URL

Example URL: http://www.example.com/blog/12/25/2013/marketing/merry-christmas?post-id=33

Original URL path : http://www.example.com/blog/:month/:day/:year/*rest-of-url?post-id=:post-id

Destination URL: http://blog.example.com/{month}-{day}-{year}/post-{post-id}/{rest-of-url}.

After saving this mapping, original example URL would redirect to: http://blog.example.com/12-25-2013/post-33/marketing/merry-christmas.

Was this article helpful?