In Javascript I can redirect and preserve the query string and fragment ID like this:
window.location = "NEW_LOCATION" + window.location.search + window.location.hash;
For sites without Javascript you can use the http-equiv meta header. But this drops the query string and fragment ID:
<head>
<meta http-equiv="Refresh" content="300; url=NEW_LOCATION" />
</head>
Is there a way to do the equivalent using http-equiv="refresh" that preserves the query string and fragment ID?
You could use JavaScript to update the meta tag with the query string and hash.
Update A better approach for IE8+ would be a noscript tag and a JavaScript powered redirect. Add the redirect as data-destination attribute on the html element so the script can grab it easily.
<!DOCTYPE html>
<html data-destination="http://stackoverflow.com">
<head>
<noscript><meta id="redirect" http-equiv="refresh" content="0; url=http://stackoverflow.com"></noscript>
</head>
<body>
This page has moved. Redirecting...
<!-- Redirect in JavaScript with meta refresh fallback above in noscript -->
<script>
var destination = document.documentElement.getAttribute('data-destination');
window.location.href = destination + (window.location.search || '') + (window.location.hash || '');
</script>
</body>
</html>
Not without a server-side scripting language which puts the proper url in the HTML tag (or sends a Refresh
header directly).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With