http:// 和 http://www 的问题

发布于 2024-08-17 19:18:32 字数 495 浏览 2 评论 0原文

我有一个托管在临时服务器上的应用程序。如果我通过提供凭据来使用我的应用程序,我可以打开 URL => http://mysite.com

但是,如果我将 URL 更改为 http://www.mysite.com,该网站将再次显示登录页面以请求凭据(我刚刚提供)。

现在,在临时服务器上,如果我在地址栏中输入 http://mysite.com,我就会被发送到 http://mysite.com。但是,当我在地址栏中输入 google.com 时,我会转到 http://www.google.com。这是怎么发生的?

我的问题是:当我的应用程序上线并输入 mysite.com 时,网址是否会转换为 http://www.mysite.com 还是我需要做些什么来将 url 转换为包含 www 的 URL?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

会发光的星星闪亮亮i 2024-08-24 19:18:32

您需要设置转发器将 www 子域转发到根域。

这里有几种方法:

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

Here's a few ways to do it:

像极了他 2024-08-24 19:18:32

如果您无法执行 Skilldrick 推荐的任何 URL 重写方法 那么您需要配置您的身份验证模块以使用正确的共享域 cookie。

如果您使用表单身份验证,则可以在 web.config 中实现:

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

注意域中的前导句点 - 这将写入一个可以从 example.com 和 www.example.com 读取的身份验证 cookie,这意味着您现在将登录该网站的两个版本。

话虽这么说,Skilldrick 给出的最后一个示例效果很好,并且对于您在站点上实现来说应该相当简单。

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.

心如狂蝶 2024-08-24 19:18:32

您似乎有几个不同的问题要问:

首先 - 为什么在输入 http://google.com 时会得到 http://www.google.com

这是因为 google 在服务器端进行重定向,因此每个访问 http://google.com 的人都会到达 http://www.google.com /

您可以通过将对 http://www.mysite.com 的每个调用重定向到 http://mysite.com 来执行相同的操作。

这可以通过使用 Response.Redirect 方法、使用 URL 重写模块或多种方法中的任何一种来实现。

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.

紫轩蝶泪 2024-08-24 19:18:32

从一个 URL 重定向到另一个 URL 可以通过多种方式进行处理。几个是:

  1. 元刷新标记,托管在 http://mysite.com 上,其中包含以下内容:< /p>

    
    
  2. URL 重写,例如使用 Apache (http://httpd.apache .org/docs/2.2/mod/mod_rewrite.htmlhttp://www .widexl.com/tutorials/mod_rewrite.html 可能是值得一看的地方):

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

    这将用于将任何与 www.mysite.com 不匹配的主机外部重定向 (HTTP 302) 到 http ://www.mysite.com
    IIS 也可能实现同样的效果。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文