tags:

views:

97

answers:

4

Hi all, I have an application which is hosted on the stage server. If i use my apllication by giving the credentials it will open the site. URL => http://mysite.com

but if i change the url to http://www.mysite.com, the site will show the login page again to enter the credentials(but the user is already logged in).

Now on the staging server, if i give http://mysite.com in the address bar its picking as http://mysite.com for eg: if i give just, google.com and enter, url will be changed to http://www.google.com. hw is this happening?

My question is, when my application goes live & if i type mysite.com, will the url gets converted to http://www.mysite.com or what is the procedure to convert the url which contains www.

+3  A: 

You need to set up a forwarder to forward the www subdomain to the root domain.

Here's one way to do it.

Here's a way on IIS.

And one more way on IIS. Really, I spoil you :)

Skilldrick
I use a method very similar to the last option to do this on various sites.
Zhaph - Ben Duguid
My IIS is 6.0 In this case will i be able to use the URL Rewriter?
A: 

You have several different issues you seem to be asking:

First off - why you get http://www.google.com when typing http://google.com:

This is because google are doing a redirect on the server side, so everyone going to http://google.com ends up at http://www.google.com/

You can do the same, by redirecting every call to http://www.mysite.com to http://mysite.com.

This can be achieved by using the Response.Redirect method, using a URL rewriting module or any of several ways.

Oded
I wouldn't issue a Response.Redirect as that only issues a Temporary Redirect (302), and some search engines don't like lots of those, it's better to use a method that produces a 301 permanent redirect as in the last example Skilldrick (http://stackoverflow.com/questions/2063293/issue-with-http-and-http-www/2063302#2063302) supplies.
Zhaph - Ben Duguid
if i take any site as an example 75%of them are adding www as prefix. I want to know whether its someting that all are handling in the code behind or can be achieved by some tricks in IIS?
Many of them only have the domain with the www prefix registered, so attempting to go to the non www will fail. Others don't do any sort of redirect and both will work.
Oded
A: 

Redirection from one URL to another can be handled in multiple ways. A couple are:

  1. Meta refresh tag, hosted at http://mysite.com that contains something like:

    <meta http-equiv="refresh" content="1;url=http://www.mysite.com"&gt;
    
  2. URL rewriting, for example with Apache (http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html and http://www.widexl.com/tutorials/mod_rewrite.html might be places to look):

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www.mysite.com$ [NC]
    RewriteRule ^(.*)$ http://www.mysite.com/$1 [R,L]
    

    This would be used to externally redirect (HTTP 302) any host that doesn't match www.mysite.com to http://www.mysite.com. The same is likely also possible with IIS.

Sychare Jedko
+2  A: 

If you're unable to perform any of the URL rewriting methods recommended by Skilldrick then you will need to configure your authentication module to use the correct shared domain cookie.

If you are using Forms authentication this can be achieved in the web.config:

<forms name="name" 
       loginUrl="URL" 
       defaultUrl="URL"
       domain=".example.com">
</forms>

Note the leading period in the domain - this writes an authentication cookie that can be read from both example.com and www.example.com, meaning that you will now be logged in on both variations of the site.

That being said, the last example that Skilldrick gives works nicely, and should be fairly trivial for you to implement on your site.

Zhaph - Ben Duguid
ok.. let me try this. before that let me ask one doubt..what would be the name="name", what does this indicate? The loginurl and default url, are they both the same?