lukas.coenig
lukas.coenig

Reputation: 551

How to pass URL parameters when redirecting to another URL?

I'm using this html code to redirect to another URL when the page (www.dasinfobuch.de/links/Wizz) is invoked:

<head>
  <meta http-equiv="refresh" content="0; URL=http://52.28.104.181:8080/Wizard/Wizz">
</head>

However, when I use a URL parameter such as

www.dasinfobuch.de/links/Wizz?template=test

the parameter is not passed on to the redirected page. Is there a way to accomplish this (preferably in plain HTML)? (I'm new to Web programming.)

Upvotes: 9

Views: 51187

Answers (1)

dakab
dakab

Reputation: 5885

This is not possible using only a meta element that mimics the non-standard Refresh HTTP header field. Of course there are other ways.

If you’ve got something like a preprocessor, you can pass on the request to the HTML, like so:

<meta http-equiv="refresh"
      content="0; URL=http://52.28.104.181:8080/Wizard/Wizz?template=<%
           out.print(request.getParameter("template")) %>">

Another (client-side) way is to redirect using JavaScript:

document.location.href = 'http://52.28.104.181:8080/Wizard/Wizz' + document.location.search;

Note that this will carry over the entire query string, not just the template parameter and its argument. If that’s a problem, it’s easy to get only the desired string from location.search.

Upvotes: 10

Related Questions