Web.config重写规则添加包含www的附加/在URL上 [英] Web.config rewrite rules adding additional / on URLS that contain www

查看:81
本文介绍了Web.config重写规则添加包含www的附加/在URL上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个拥有SSL的网站,当用户访问我们的网站时,我会自动删除 www



所以当用户输入 www.my-example.com 时,他们会被重定向到 https://my-example.com



以下是我为实现此目的而编写的规则。



< rule name =删除www。> 
< match url =(。*)/>
< conditions>
< add input ={HTTP_HOST}pattern =^ www。(。*)/>
< / conditions>
< action type =Redirecturl =http:// {C:1} / {URL}/>
< / rule>





这在大多数情况下工作正常,但我遇到了问题。我们有很多外部资源链接到我们制作的各个页面: https://www.my-example.com/example-post



它正确删除了 www ,但在示例帖子之前附加了第二个 / 。所以上面的网址会重定向到 https://my-example.com//example-post



我需要这个不发生。有什么建议吗?



我的尝试:



我只有我的web.config文件中有2个重写规则。这里它们按原样



< rule name =强制HTTPS重定向enabled =truestopProcessing =true> 
< match url =^ $ignoreCase =false/>
< conditions>
< add input ={HTTP_HOST}pattern =localhostnegate =true/>
< add input ={HTTPS}pattern =^ OFF $/>
< / conditions>
< action type =Redirecturl =https:// {HTTP_HOST} /redirectType =Permanent/>
< / rule>
< rule name =删除www。>
< match url =(。*)/>
< conditions>
< add input ={HTTP_HOST}pattern =^ www。(。*)/>
< / conditions>
< action type =Redirecturl =http:// {C:1} / {URL}/>
< / rule>

解决方案

ignoreCase =false/>
< conditions>
< ; add input ={HTTP_HOST}pattern =localhostnegate =true/>
< add input ={HTTPS}pattern =^ OFF


< blockquote>/>
< / conditions>
< action type =Redirecturl =https:// {HTTP_HOST} /redirectType =Permanent/>
< / rule>
< rule name =删除www。>
< match url =(。*)/>
< conditions>
< add input ={HTTP_HOST}pattern =^ www。(。*)/>
< / conditions>
< action type =Redirecturl = http:// {C:1} / {URL}/>
< / rule>


I have a website that has an SSL that I automatically remove the beginning www from when a user visits our site.

So when a user types in www.my-example.com they are redirected to https://my-example.com

Here is the rule I wrote to achieve this.

<rule name="Remove www.">
   <match url="(.*)" />
   <conditions>
     <add input="{HTTP_HOST}" pattern="^www.(.*)" />
   </conditions>
   <action type="Redirect" url="http://{C:1}/{URL}" />
 </rule>



This works fine in most cases but I'm running into an issue. We have many outside sources linking to individual pages we made like this: https://www.my-example.com/example-post

It correctly removes the www but appends a second / before the example post. So the above url would redirect to https://my-example.com//example-post

I need this to not happen. Any suggestions?

What I have tried:

I only have 2 rewrite rules in my web.config file. Here they are as is

<rule name="Force HTTPS Redirection" enabled="true" stopProcessing="true">
  <match url="^$" ignoreCase="false"/>
  <conditions>
    <add input="{HTTP_HOST}" pattern="localhost" negate="true" />
    <add input="{HTTPS}" pattern="^OFF$"/>
  </conditions>
  <action type="Redirect" url="https://{HTTP_HOST}/" redirectType="Permanent"/>
</rule>
<rule name="Remove www.">
  <match url="(.*)" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^www.(.*)" />
  </conditions>
  <action type="Redirect" url="http://{C:1}/{URL}" />
</rule>

解决方案

" ignoreCase="false"/> <conditions> <add input="{HTTP_HOST}" pattern="localhost" negate="true" /> <add input="{HTTPS}" pattern="^OFF


"/> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/" redirectType="Permanent"/> </rule> <rule name="Remove www."> <match url="(.*)" /> <conditions> <add input="{HTTP_HOST}" pattern="^www.(.*)" /> </conditions> <action type="Redirect" url="http://{C:1}/{URL}" /> </rule>


这篇关于Web.config重写规则添加包含www的附加/在URL上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆