简体   繁体   English

IIS 10中的URL重写问题

[英]Issues with URL Rewrite in IIS 10

I'm going to start out with stating that I don't understand how to use regular expression, and I don't have the time to learn it in the near future. 首先,我要说的是我不懂如何使用正则表达式,并且我没有时间在不久的将来学习它。 I've read an article that explains how to do exactly what I need, but when I try and do it, it simply isn't working and breaks the webpage completely (404 errors). 我读过一篇文章,解释了如何准确地执行所需的操作,但是当我尝试执行操作时,它根本无法正常工作,并且完全破坏了网页(404错误)。 Here's the article: IIS url rewrite role except some urls 这是文章: IIS URL重写角色,除了一些URL

My issue is, when I create the rewrite in the GUI, even if I type in the website and use 'exact match' instead of 'regular expression', it doesn't rewrite the URL the what it should (or the way I think it should, which I'm obviously wrong). 我的问题是,当我在GUI中创建重写时,即使我在网站上键入并使用“完全匹配”而不是“正则表达式”,它也不会以应有的方式(或我认为的方式)重写URL应该,我显然是错误的)。

What I want to do: 我想做的事:

  • If the client goes to myweb.site.com then redirect to myweb.site.com/login 如果客户端转到myweb.site.com则重定向到myweb.site.com/login
  • Except when going directly to myweb.site.com/thispage.aspx 直接进入myweb.site.com/thispage.aspxmyweb.site.com/thispage.aspx

Here's the snip from the config file: 这是配置文件中的片段:

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

I'd prefer to do this in the GUI, but if I absolutely must manually edit the config then I'll do so. 我希望在GUI中执行此操作,但是如果我绝对必须手动编辑配置,则可以这样做。

Thanks in advance for any help! 在此先感谢您的帮助! Sorry for not being more knowledgeable! 对不起,我不了解!

In your case rule should be like that: 在您的情况下,规则应如下所示:

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

This rule will redirect http://myweb.site.com to https://myweb.site.com/login only. 该规则仅将http://myweb.site.com重定向到https://myweb.site.com/login

It will NOT redirect https://myweb.site.com to https://myweb.site.com/login . 不会https://myweb.site.com重定向到https://myweb.site.com/login (If you want to allow that , just remove condiitons section) (如果要允许这样做,只需删除condiitons部分)

In this line <match url="^$" /> url attribute should contains pattern for url path. 在此行<match url="^$" /> url属性应包含url路径的模式。 In your case url path is empty(becasuse it is homepage), and regexp ^$ means empty string 在您的情况下,URL路径为空(因为它是主页),而regexp ^$表示空字符串

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM