【问题标题】:Redirect to subdomain using web.config rules使用 web.config 规则重定向到子域
【发布时间】:2020-08-14 11:45:09
【问题描述】:

我们迁移托管在主域内目录“webapp”中的 webapp:

http://www.example.com/webapp/

到没有“webapp”文件夹的新子域:

http://subdomain.example.com/

我只需要重定向子目录“webapp”。我不想重定向其他网址,例如http://www.example.com/http://www.example.com/folder1http://www.example.com/folder2、...。

但我们已经向客户发送了很多电子邮件,其中包含以下链接:<a href="http://www.example.com/webapp/login">LOGIN TO YOUR DASHBOARD</a> 或其他链接,例如 <a href="http://www.example.com/webapp/data/download.php/id=xxx">DOWNLOAD YOUR DOC</a>

现在我正在尝试通过 web.config 进行重定向,但似乎没有任何效果。

如果我尝试不导航到,例如 http://www.example.com/webapp/login,我不会按预期重定向到 http://subdomain.example.com/login/

如果我尝试不导航到,例如 http://www.example.com/webapp/data/download.php/id=43,我不会按预期重定向到 http://subdomain.example.com/data/download.php/id=43

有什么建议吗?

<rule name="redirect-to-subdomain" stopProcessing="true">
    <match url="^webapp/$" />
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Redirect" url="http://subdomain.example.com/{R:0}" redirectType="Permanent" />
</rule>

【问题讨论】:

    标签: asp.net redirect iis web-config


    【解决方案1】:

    除了http://www.example.com/webapp/,您的规则无效。

    如果您想重定向链接,例如http://www.example.com/webapp/login。请试试这个规则。

    <rule name="redirect-to-subdomain" stopProcessing="true">
        <match url="^webapp/(.*)$" />
        <conditions>
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
        <action type="Redirect" url="http://subdomain.example.com/{R:1}" redirectType="Temporary" />
    </rule>
    

    【讨论】:

      猜你喜欢
      • 2012-12-11
      • 2019-08-02
      • 1970-01-01
      • 1970-01-01
      • 2015-01-26
      • 2012-05-07
      • 1970-01-01
      • 2016-11-10
      • 1970-01-01
      相关资源
      最近更新 更多