0

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

alice7
  • 3,834
  • 14
  • 64
  • 93
  • an http redirect is an http redirect - it's not specific to IIS or any other server. Are you asking about how to redirect someone without using IIS? – Sam Dufel Sep 25 '12 at 23:01
  • Yes, I was trying to ask any other sort of mechanism to redirect a user to my login page when they don't type the correct url. – alice7 Sep 25 '12 at 23:04
  • 1
    I see that C# tag, makes me think this is ASP.Net. If it is, are you using the built in authentication stuff? If so, you can specify the login page url in that configuration, so anyone that isn't logged in will get redirected to the login if they're trying to access a resource that requires a user to be authorized. Hard to tell though since there isn't any code or much more explanation in the question. – Gromer Sep 25 '12 at 23:08
  • I was trying to find out a way to redirect a user when he enters www.mywebsite.com to www.mywebsite.com/login automatically. Using IIS, http redirect you can achieve by setting at default web site level in IIS by redirecting a user to a destination url. I was wondering, is there any other way like that? – alice7 Sep 26 '12 at 05:09
  • I was looking for something like this: http://stackoverflow.com/questions/7018818/iis7-url-redirection-from-root-to-sub-directory – alice7 Oct 01 '12 at 20:11

3 Answers3

2

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>
Andreas Rehm
  • 2,222
  • 17
  • 20
0

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:

Classic ASP. Call it "Index.asp"

<% Response.Redirect("http://mywebsite.com/login") %>

PHP, call it "index.php"

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

Dai
  • 141,631
  • 28
  • 261
  • 374
0

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?

Community
  • 1
  • 1
Lifes
  • 1,226
  • 2
  • 25
  • 45