I was wondering, what are the ways by which I can redirect any user from http://www.mywebsite.com to http://www.mywebsite.com/login without using IIS http redirect.
Thanks
I was wondering, what are the ways by which I can redirect any user from http://www.mywebsite.com to http://www.mywebsite.com/login without using IIS http redirect.
Thanks
You can just use html code to do this:
<html>
<head>
<meta http-equiv="refresh" content="5; URL=http://www.mywebsite.com/login">
</head>
<body>
Please wait - redirecting...
</body>
</html>
The content part describes what to do. The first number is the time when the redirect should start. Here it's 5 seconds. The URL= part tells the browser where to go.
The second approach will be using javascript with body.onload:
<html>
<head>
</head>
<body onLoad='location.href="http://www.mywebsite.com/login"'>
Please wait - redirecting...
</body>
</html>
By "IIS redirect" I assume you're referring to IIS's "redirect all requests to this filesystem directory" feature. Since IIS7 this configuration has been stored in the web.config
or applicationHost.config
files. In IIS6 this was stored in the binary metabase.
If you want something cheap and nasty, you can use a Classic ASP or PHP script, like so:
<% Response.Redirect("http://mywebsite.com/login") %>
<?php header("Location: http://mywebsite.com/login"); header("Status: 303 See Other"); %>
Note that the PHP redirection is more portable than ASP, as it should work with most Apache servers. Note my use of the semantically correct HTTP 303 redirect, rather than the incorrect 301 or 302 redirect (which Classic ASP uses).
There are also HTML/Javascript-based redirects, but they aren't true redirects as the client gets a HTTP 200 response initially.
You can always do this using JavaScript. Put a script section in your html header with the following code:
<head>
<script type="text/javascript">
window.location.href = "http://stackoverflow.com";
</script>
</head>
For more info: How to redirect to another webpage in JavaScript/jQuery?