HTML - How http-equiv="refresh" redirects to a page without full URL?

10,227

Solution 1

Have you tried

<meta http-equiv="REFRESH" content="0; url=https://mydomain.com:443/main.html">

Solution 2

It appears that you need the redirect to be using HTTP in your dev environment and HTTPS through the proxy. The most effective way is using a protocol-relative URL starting with //:

<meta http-equiv="REFRESH" content="0; url=//mydomain.com/main.html">

The obvious limitation is that the port can't be explicitly set in the URL, as it depends on the protocol. If you never intend to use port 80 on the dev server, you can set up a virtual host for your dev server's config (http://mydomain.com) on port 80 which redirects to port 8080:

<VirtualHost *:80>
    Redirect / http://mydomain.com:8080/
</VirtualHost>

(The above is for Apache using mod_alias. ISS and other servers should have similar abilities.)

Additionally, you may direct all traffic to HTTPS using a virtual host on both port 80 and port 8080. I have portions of my site set up this way, which ensures that all traffic to sensitive areas are through SSL (HTTPS).

<VirtualHost *:80>
    Redirect / https://mydomain.com/
</VirtualHost>
<VirtualHost *:8080>
    Redirect / https://mydomain.com/
</VirtualHost>

The port numbers can also be included like Redirect / https://mydomain.com:443/, but browsers will assume port 443 for an HTTPS address, so it's only needed if your SSL connections go through an alternative port.

Share:
10,227
ipohfly
Author by

ipohfly

a developer

Updated on June 05, 2022

Comments

  • ipohfly
    ipohfly almost 2 years

    I have a html page index.html with the following in the <HEAD> tag to redirect the user to another page when accessed:

    <meta http-equiv="REFRESH" content="0; url=main.html">
    

    This works fine in our development environment. However when we move the page to behind a proxy server with SSL termination, the URL is different instead, i.e. when accessing https://mydomain.com:443/index.html it will redirect to main.html with this URL http://mydomain.com:8080/main.html which is not what we expected.

    My question is, how does the http-equiv get the complete URL path since we're not specifying it, and whether it has anything to do with the end result where the actual port of the application server is being used in the browser, rather than the reverse proxy's port and protocol.

    Thank you.