Blog, Website & Page Publishing

craigcri
Member

Redirect URL with or without the full query string

Hey HubSpot!

We have a Flexible Redirect set up for a specific URL:

 

URL A:

https://www.example.com/page/test?query1=1&query2=2&query3=3

 

URL B:

https://subdomain.example.com/page/test?query1=1&query2=2&query3=3

 

I have created a flexible redirect that redirects these two just fine, but the current problem is that if a user visits URL A without the query parameters, the redirect fails to trigger... My first thought was to set up a sort of fallback redirect url, one where A and B did not include any query string, but the tool detects this as a duplicate and doesn't allow it to be created.

 

My hope is to use a flexible redirect ruling that essentially takes a string and replaces it directly to the redirect url, regardless if its empty, contains extra variables, or is missing some. Here's an example of what ultimately I think would solve the problem, what I'm hoping it would look like in HubSpot's redirect builder:

 

Original Url:

https://www.example.com/page/test*wildcard_string

 

Redirect URL:

https://subdomain.example.com/page/test{wildcard_string}

 

...the only problem is, the above solution does not work as expected.

 

Basically, because in certain cases, this url can be altered by adblock plugins or user error,  we still want the redirect to happen, thus we need the URL Redirect to occur with or without the full query string.

 

Does anyone know of a solution to something like this?

1 Reply 1
ajchapman20
Top Contributor | Diamond Partner
Top Contributor | Diamond Partner

Redirect URL with or without the full query string

Hi @craigcri ,

I understand that you currently have a redirect set up which specifies query parameters. However, when these parameters do not exist, the redirect no longer works. You mentioned creating a fallback redirect without the paramters from URL A to B, but the system recognizes this a duplicate.

 

The second option that you have created which does not seem to be working is as follows;

 

Original Url:

https://www.example.com/page/test*wildcard_string

Redirect URL:

https://subdomain.example.com/page/test{wildcard_string}

 

If you take a look to this documentation here, it reads " Each piece of the URL path between the forward slashes of each subdirectory / / must have its own component 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 star symbol * followed by a name for the rest of the URL. Any non-component text in the destination URL will not be dynamically replaced."

 

To put this into context, try and change the redirect URL to https://subdomain.example.com/page/test/{wildcard_string} - note the extra forward slash here between test and {wildcard-string}.

 

Let me know if it then works for you! You should also note that sometimes URLs can take a bit of time to register, and in some cases you may need to clear your cache too. If you would like to send me on the URLs that you are working on too, I am happy to test these on my end.

Alex Chapman | Inbound marketing Expert
0 Upvotes