IIS网址重写 [英] IIS Url-Rewrite

查看:244
本文介绍了IIS网址重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用IIS7网址重写模块重写 services.mydomain.com/some-file-here mydomain.webhost.com/folder/some-file-here

I'm trying to use IIS7 Url Rewrite module rewrite services.mydomain.com/some-file-here to mydomain.webhost.com/folder/some-file-here

规则如下:

Pattern = ^services.mydomain.com/(.*)$
Action = Rewrite
Rewrite URL = http://mydomain.webhost.com/folder/{R:1}

问题是IIS不断给我404找不到错误.我已经被这个问题困扰了好几天了.有什么想法吗?

The problem is IIS keeps giving me 404 not found errors. I've been stuck at this for days now. Any ideas?

推荐答案

您的模式错误.它不应在其中包含域名或查询字符串-仅包含路径而不带斜杠.请参阅下面的工作规则:

You have your pattern wrong. It should not include domain name or query string there -- only path without leading slash. See the working rule below:

<rule name="MyRewriteRule" stopProcessing="true">
    <match url="^(some-file-here)$" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^services\.mydomain\.com$" />
    </conditions>
    <action type="Redirect" url="http://mydomain.webhost.com/folder/{R:1}" />
</rule>

仅当主机名是services.mydomain.com时,才会触发上述规则.如果不需要这种附加条件(可选),则只需删除以下3行:<conditions>...</conditions>

The above rule will only trigger if host name is services.mydomain.com. If you do not require such additional condition (which is optional) then just remove these 3 lines: <conditions>...</conditions>

此外,以上规则将只执行一次从services.mydomain.com/some-file-heremydomain.webhost.com/folder/some-file-here的特定重定向.如果您需要像这样重定向任何文件,请改用此文件:

Also, the above rule will only do one specific redirect from services.mydomain.com/some-file-here to mydomain.webhost.com/folder/some-file-here. If you need to redirect ANY file like that, then use this one instead:

<rule name="MyRewriteRule" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^services\.mydomain\.com$" />
    </conditions>
    <action type="Redirect" url="http://mydomain.webhost.com/folder/{R:1}" />
</rule>

这篇关于IIS网址重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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