IIS将非WWW连同HTTP重定向到WWW到HTTPS ISSUE

编程入门 行业动态 更新时间:2024-10-26 04:25:44
本文介绍了IIS将非WWW连同HTTP重定向到WWW到HTTPS ISSUE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在IIS 8.5中将非WWW连同HTTP重定向到WWW到HTTPS.如果用户键入 example ,则 www.example 或 example ,它们都重定向到 www.example .

I want to redirect non-WWW to WWW along with HTTP to HTTPS in IIS 8.5. if users type example, www.example, or example, they all redirect to www.example.

这是我的web.config文件

This is my web.config file

<rewrite> <rules> <rule name="Force WWW and SSL" enabled="true" stopProcessing="true"> <match url="(.*)" /> <conditions logicalGrouping="MatchAny"> <add input="{HTTP_HOST}" pattern="^[^www]" /> <add input="{HTTPS}" pattern="off" /> </conditions> <action type="Redirect" url="www.example/{R:1}" appendQueryString="true" redirectType="Permanent" /> </rule> </rules> </rewrite

请注意,在IIS中,我只有1个绑定,即example,问题是:对于所有重定向到 www.example ,但IIS的起始页不是我的Default.aspx,当我键入 www.example/Default.aspx 会显示404错误.

Please note that in IIS i have ONLY 1 binding which is example, The problem is : for all the urls it redirects to www.example BUT the start page of IIS appears not my Default.aspx, and When i type www.example/Default.aspx it gives 404 Error.

推荐答案

您将需要将每个主机名绑定到一个网站.未明确绑定到网站(或服务器IP地址)的任何主机名将由IIS中的默认网站处理(绑定 * -表示未绑定到正在运行的网站的任何主机名).

You will need to bind each hostname to a website. Any hostnames not specifically bound to a website (or the servers IP address) will be handled by the Default Website in IIS (binding * - meaning any hostname not bound to a running Website).

一个不错的简单设置是在IIS中创建2个网站(将其称为 Application 和 Rewrites )-一个用于托管您的应用程序,第二个用于处理其他域的重写到您的主域.您绑定到 Rewrite 网站的任何域都会将其流量重定向到 www.example .

A nice easy setup is to create 2 Websites in IIS (lets call them Application and Rewrites) - one to host your application, a second to handle rewriting other domains to your primary domain. Any domain you bind to the Rewrite Website will redirect its traffic to www.example.

  • 仅在端口443上绑定您的应用程序主机名 www.example (仅SSL)
  • 将您的应用程序部署到此webroot
  • 在IIS中创建一个新网站,并为其webroot创建一个新文件夹.
  • 在端口443和端口80上绑定 example .也仅在端口80上绑定 www.example .
  • Create a new Website in IIS, and create a new folder for its webroot.
  • Bind example on port 443 and port 80. Also bind www.example on port 80 only.

在 Rewrite 网站webroot文件夹中创建一个web.config,如下所示:

Create a web.config in the Rewrite Website webroot folder as follows:

<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="Redirect any traffic to Primary hostname" enabled="true" stopProcessing="true"> <match url="(.*)" /> <action type="Redirect" url="www.example/{R:1}" appendQueryString="true" redirectType="Permanent" /> </rule> </rules> </rewrite> </system.webServer> </configuration>

访问 example , example 或 www.example 将重定向到 www.example (包括任何路径/查询字符串)

Any traffic accessing example, example, or www.example will be redirected to www.example (including any path/query string)

注意:您可以将默认网站用作 Rewrite 网站,或将通配符 * 绑定从默认网站移至新的 Rewrite 网站-将任何域重定向到您的 www.example -但这是一种不好的做法/不建议.

NOTE: You could use the default website as the Rewrite website, or move the wildcard * binding from the default website to a new Rewrite website - to redirect any domain to your www.example - however this is bad practise / not advised.

更多推荐

IIS将非WWW连同HTTP重定向到WWW到HTTPS ISSUE

本文发布于:2023-11-02 08:34:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551909.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   WWW   IIS   HTTP   ISSUE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!