我想在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
发布评论