IIS 7.5 URL重写 - 从URL重写文件夹 [英] IIS 7.5 URL Rewrite - Rewrite a Folder from an URL

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

问题描述

我使用IIS 7.5和URL重写。

I use IIS 7.5 and URL Rewrite.

我的网站具有以下文件层次结构:

I have a website with the following file hierarchy:

webroot
webroot/LegacySite

两个webroot /和legacy /是IIS中的单独App-Folders。

Both webroot/ and legacy/ are separate App-Folders in IIS.

我需要重写我的网址:

  • If a request is http://mysite.co/LegacySite/page.aspx the URL will be rewritten to http://mysite.co/page.aspx

在我的 Web.Conf下面 (在webroot文件夹中)无法正常工作,你能指出我缺少的东西吗?

Below my Web.Conf (in the webroot folder) does not work properly, could you point out what I'm missing?

<?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="MyRole" stopProcessing="true">
                        <match url=".*" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="^mysite.com" />
                            <add input="{PATH_INFO}" pattern="^\LegacySite\" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="\LegacySite\{R:0}" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>


推荐答案

以下情况应该有效:

<rule name="MyRole" stopProcessing="true">
    <match url="LegacySite/(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^mysite.com$" />
    </conditions>
    <action type="Rewrite" url="/{R:1}" appendQueryString="true" />
</rule>

您可能希望删除检查主机名的条件。这真的很重要吗?您是否有任何其他域名绑定到您不希望重定向发生的网站?这似乎没必要。您可能只需要:

You might want to drop the conditional for checking the host name. Is that really important? Do you have any other domain names bound to that website for which you don't want the redirect to happen? It seems unnecessary. You probably only need:

<rule name="MyRole" stopProcessing="true">
    <match url="LegacySite/(.*)" />
    <action type="Rewrite" url="/{R:1}" appendQueryString="true" />
</rule>

我添加了 appendQueryString =true将任何(可选的)查询字符串参数传递给重写的URL。

I've added appendQueryString="true" to pass any (optional) query string parameters to the rewritten URL.

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

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