APIs & Integrations

svigneault
Participant

How to redirect a URL that contains an argument

Our software’s Help documentation is gated in a folder on a Microsoft box. The URL that the software pushes to call the documentation is sent with an argument. How do we ensure an argument remains with a redirect?

For example, domain www.mybusiness.com is being transferred from Windows box server to Hubspot. But the URL, www.mybusiness.com/help?A=V needs to be redirected to another URL, help.mybusiiness.com, on the old server where the gated documents live.

How do I do this?

0 Upvotes
2 Replies 2
galewinston
Member

How to redirect a URL that contains an argument

You can redirect a web page via JavaScript using a number of methods. window.location.replace(...) is better than using window.location.href, because replace() does not keep the originating page in the session history, meaning the user won't get stuck in a never-ending back-button fiasco.

 

  • If you want to simulate someone clicking on a link, use location.href
  • If you want to simulate an HTTP redirect, use location.replace

JavaScript redirect example:

// similar behavior as an HTTP redirect
window.location.replace("http://example.com");

// similar behavior as clicking on a link
window.location.href = "http://example.com";

 

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

How to redirect a URL that contains an argument

@svigneault Could you grab the parameter from your current URL right before you make the call and then add it to the call to the new site? You can read up on using the window location object in Javascript.

http://www.w3schools.com/js/js_window_location.asp

Essentially you can in the end make a window.href(“Insert new website with parameter here”); call

To expand on this.

Step 1. Grab the parameter from the current URL

Step 2. Add that parameter to the redirect call.

Step 3. Make redirect call

steps 2 and 3 can be done at the same time.

0 Upvotes