Preserve a query string at the end of a short URL (bit.ly | YOURLS), and preserve it on the resolved URL

1k Views Asked by At
  • Im trying to create a simple snippet using HTML, JavaScript, and PHP.
  • A search bar, and a button.
  • Just type something into the search bar, click search and have it search google.com.
  • The button adds a query string to the end with the text entered.
  • Example: if you type "dogs" into the search bar, and hit search, it will load a new tab, and go to "https://www.google.com/search?q=dogs"*

Here is the problem

  • I am using a URL shortner (like bit.ly), but self hosted on my own server called YOURLS.

  • My current snippet is now rendered useless because it does not preserve the query string from..

    • search bar string > short link > back to long url.

Recreating the problem

  1. I find a link to shorten: https://www.google.com/search/
  2. I shorten: https://www.google.com/search/ to https://sho.rt/Google/
  3. I then create my snippet with the https://sho.rt/Google/ URL
</form method="GET" action="sho.rt/Google" _lpchecked="1">
  </input type="text" placeholder="What would you like to find on google?" name="?q=">
  </button type="submit" id="submit">Search</button>
</form>

Can any of you think of a clever solution to this problem?

  • How do I use query string on a short link...and preserve it on the destination address.

  • Can this be done in HTML, JavaScript, or PHP? ...Or do I need to adjust something within the self hosted URL shortner "YOURLS"?

You are likely thinking, why even add the addition step of shortening the URL...here is why...

  • I have a public HTTPS website (password protected & only accessed by me) with HTTP links on it (hosted within an intranet - secure). This causes a mixed-content warning message since chrome does not understand the HTTP links within an intranet and not public. I found a little workaround...I used a URL shortner tool (it takes an HTTP link, shrinks it, and also adds HTTPS to the short link). I then replaced all the HTTP long urls on my site, with the short HTTPS links, and my site no longer has mixed service, and is secure. This solves 99% of my problems. All that's left is getting my short URLs to preserve the query string to the long URL.
0

There are 0 best solutions below