2017-07-10 53 views
0

URL重写问题我会跟指出,我​​不知道如何使用正则表达式开始了,我没有了解它在不久的将来的时间。 我读过一篇文章,解释了如何完成我所需要的功能,但是当我尝试去做,它根本无法正常工作,并完全打破了网页(404错误)。 这里的文章:IIS url rewrite role except some urls在IIS 10

我的问题是,当我在GUI中创建重写,即使我输入网站并使用'完全匹配'而不是'正则表达式',它不会重写URL它应该如何(或者我认为应该的方式,我显然是错误的)。

我想做什么:

  • 如果客户去myweb.site.com然后重定向到myweb.site.com/login
  • 直接进入myweb.site.com/thispage.aspx

这里的时候,除了是从配置文件中的SNIP:

<rules> 
      <rule name="Redirect to Client Login on root lookup" enabled="true" patternSyntax="ExactMatch" stopProcessing="true"> 
       <match url="https://myweb.site.com" /> 
       <conditions logicalGrouping="MatchAny"> 
        <add input="{QUERY_STRING}" pattern="https://myweb.site.com/Default.aspx" negate="true" /> 
       </conditions> 
       <action type="Rewrite" url="https://myweb.site.com/login" /> 
      </rule> 

我d更喜欢在GUI中这样做,但如果我绝对必须手动编辑配置,那么我会这样做。

在此先感谢您的帮助!对不起,没有更多的知识!

+0

''应该只包含资源路径和可选的查询字符串,它不应该包含URI方案('http:'或'https')或主机名和端口号('myweb.site.com')。 – Dai

+0

您还有'{QUERY_STRING}'输入条件中的完整网址。查询字符串是'?'字符后面的部分。 – Dai

+0

请澄清,如果你想'/'重写为'/ login'或重定向到'/ login'。我认为重定向更有意义,否则您将有两个具有相同响应内容的URL,这可能会让用户感到困惑。 – Dai

回答

0

在你的情况的规则应该是这样的:

<rule name="root to login" stopProcessing="true"> 
    <match url="^$" /> 
    <conditions> 
     <add input="{HTTPS}" pattern="off" /> 
    </conditions> 
    <action type="Redirect" url="https://myweb.site.com/login" appendQueryString="true" redirectType="Permanent" /> 
</rule> 

此规则将重定向http://myweb.site.comhttps://myweb.site.com/login

它会不是重定向https://myweb.site.comhttps://myweb.site.com/login。 (如果你想允许的话,只需删除condiitons部分)

在这一行<match url="^$" /> url属性应该包含url路径的模式。在你的情况下,url路径是空的(因为它是主页),并且正则表达式^$表示空字符串