Reputation: 1
I have an application which is hosted on a staging server. If I use my application by providing my credentials, I can open URL => http://mysite.com
.
However, if I change the url to http://www.mysite.com
, the site shows the login page again to request the credentials (which I have just provided).
Now on the staging server, if I type http://mysite.com
in the address bar, I get sent to http://mysite.com
. But when I type google.com into the address bar, I get taken to http://www.google.com
. How is this happening?
My question is: when my application goes live and I type mysite.com
, will the url get converted to http://www.mysite.com
or do I need to do something to convert the url to one containing www
?
Upvotes: 0
Views: 229
Reputation: 70819
You need to set up a forwarder to forward the www
subdomain to the root domain.
Here's a few ways to do it:
Upvotes: 6
Reputation: 26956
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.
Upvotes: 3
Reputation: 635
Redirection from one URL to another can be handled in multiple ways. A couple are:
Meta refresh tag, hosted at http://mysite.com that contains something like:
<meta http-equiv="refresh" content="1;url=http://www.mysite.com">
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.
Upvotes: 0
Reputation: 498992
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.
Upvotes: 1