0
  • 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.
JamesReed68
  • 399
  • 2
  • 14
  • 1
    Of course this needs to be handled by the URL shortener in the first place. If that does not pass the parameter on while redirecting to your target URL, then the info is simply lost to you at that point. – CBroe Apr 09 '20 at 08:41
  • Thanks so much for your answer. Now I know which avenue to search for a solution within YOURLS. Thanks again! :) – JamesReed68 Apr 09 '20 at 08:47
  • [Minecraftchest1](https://stackoverflow.com/users/13683677) posted an [Answer](https://stackoverflow.com/a/66785819) saying "You may want to look at either [https://github.com/jessemaps/yourls-query-string-keeper](https://github.com/jessemaps/yourls-query-string-keeper) or [https://github.com/llonchj/yourls_plugins](https://github.com/llonchj/yourls_plugins). Both are YOURLS plugins." – Scratte Mar 27 '21 at 00:31

0 Answers0