8

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.)

8
  • 2
    Not possible in plain HTML, but this would be much better done on server side using a 30x redirect (using a server side programming language or a Apache Redirect in a .htaccess file as shown here)
    – Pekka
    Commented Jul 24, 2015 at 6:56
  • 1
    @Pekka웃 Ok, I'll look into that, thanks! But this would have to be done on the Server hosting www.dasinfobuch.de, right? I don't think I have this kind of access on that server (the servlet is running on a different sever). Commented Jul 24, 2015 at 7:01
  • 1
    Yes, that would have to be done on that server. If all you can access is the page source code your only option is to use JavaScript, which is less reliable (JS can be deactivated or may not be parsed at all, e.g. by bots like search engine crawlers).
    – Pekka
    Commented Jul 24, 2015 at 7:11
  • 1
    You could also parse the HTTP_REFERER header on the receiving server (the 52.28.... one). That wouldn't be 100% reliable either, as clients can turn this offf, but relatively pain free
    – Pekka
    Commented Jul 24, 2015 at 7:14
  • 1
    The referer has nothing to do with JavaScript, but is another HTTP header field. It’s the address of the resource that linked to the destination. Take a look inside request.getHeader("referer").
    – dakab
    Commented Jul 24, 2015 at 8:27

1 Answer 1

10

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.

5
  • Thanks, I'll look into that... As I said, I'm new to web programming, so it might take a while :-) (Ok, the first idea should be easy to test...) Commented Jul 24, 2015 at 7:29
  • 1
    @lukas.coenig: Don’t worry and take your time. It’s definitely a solvable problem with multiple approaches. If it still doesn’t work, providing an actual (servlet) code sample might be helpful to all.
    – dakab
    Commented Jul 24, 2015 at 7:37
  • The first thing didn't work. Obviously I don't have a preprocessor available... The result is just: 52.28.104.181:8080/Wizard/…( Commented Jul 24, 2015 at 8:43
  • If it’s a servlet, that probably means you use JavaServer Pages, which means that your HTML code might be processed, which allows you to include data from the request (like a query string) in the otherwise static HTML contents, using delimiters like <%…%>. As stated above, more information on your part is necessary, like how the page at www.dasinfobuch.de/links/Wizz is being generated and delivered…
    – dakab
    Commented Jul 24, 2015 at 9:31
  • I'm using a servlet, but without JSP - so far, on the target server site (which is running a Tomcat8). The page www.dasinfobuch.de/links/Wizz is static, I can put there whatever I want, and I need it only once (or a "finite" number of times :-)), but the server is just a standard web hosting server (by 1und1, Germany) which is not very flexible. So far, I've done all the programming on the Tomcat, nothing on the client side or the other server. Commented Jul 24, 2015 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.