如何重写URL在asp.net子,而不实际创建服务器子域 [英] How to rewrite URL as subdomain in asp.net without actually creating a subdomain on server

查看:110
本文介绍了如何重写URL在asp.net子,而不实际创建服务器子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望这不是我第一次问这个问题上左右。

I hope this isn't the first time i'm asking this question on SO.

我的网址已经在我的网站和使用查询字符串
例如: <一个href=\"http://foo.com/xyzPage.aspx?barvalue=yehaa\">http://foo.com/xyzPage.aspx?barvalue=yehaa

I've URLs in my website and which are using query string values For example: http://foo.com/xyzPage.aspx?barvalue=yehaa

http://yehaa.foo.com/

http://yehaa.foo.com/

请说明它是如何实现的而不实际创建服务器子域 ..

Please suggest how it can be accomplished without actually creating subdomains on server ..

我有 IIS 7.5 安装的服务器上,并使用 Asp.net 4.0

I've IIS 7.5 installed on server machine and using Asp.net 4.0.

非常感谢

推荐答案

修改下面我们的看法:

要访问 http://foo.com/xyzPage.aspx?barvalue=yehaa 使用 http://yehaa.foo.com/ ,你必须使用以下规则:

To access http://foo.com/xyzPage.aspx?barvalue=yehaa using http://yehaa.foo.com/, you have to use the following rule:

<rules>
    <rule name="Rewrite subdomains">
        <match url="^/?$" />
        <conditions>
            <add input="{HTTP_HOST}" pattern="^(.+)\.foo\.com$" />
        </conditions>
        <action type="Rewrite" url="http://foo.com?barvalue={C:1}" />
    </rule>
</rules>

,每天网址结尾匹配或不与 / 和使用的东西之前, foo.com ,然后重写它到 http://foo.com?barvalue= {C:1} ,其中 {C:1} 是什么值前 foo.com 输入。

It matches every url ending or not with a / and using something before foo.com and then rewrites it to http://foo.com?barvalue={C:1} where {C:1} is whatever value was entered before foo.com.

如果您直接访问到 http://foo.com?barvalue=要prevent人{C:1} ,您可以使用规则下文。

If you want to prevent people from accessing directly to http://foo.com?barvalue={C:1}, you can use the rule below.

您可以通过在你的<$ C $添加以下规则使用重写模块为IIS C>的web.config 文件:

You could use the Rewrite module for IIS by adding the following rule in your web.config file:

<rewrite>
    <rules>
        <rule name="Redirect to Subdomains" stopProcessing="true">
            <match url="^xyzPage.aspx$" />
            <conditions>
                <add input="{QUERY_STRING}" pattern="^barvalue=(.+)$" />
            </conditions>
            <action type="Redirect" url="http://{C:1}.{HTTP_HOST}" appendQueryString="false" />
        </rule>
    </rules>
</rewrite>

它检查的URL(之前或之后没有)恰好 xyzPage.aspx 相匹配。结果
它检查查询字符串包含 barvalue 参数(只有这一个),如果它的值不为空。结果
如果这些2个条件都OK,它触发重定向 http://barvalue.original.host

It checks if the url matches exactly xyzPage.aspx (nothing before or after).
It checks if the querystring contains the barvalue parameter (and only this one) and if its value is not empty.
If those 2 conditions are ok, it triggers the Redirect to http://barvalue.original.host.

您的问题指定重写,因此,如果这真的是你想要做什么,改变行动键入=重定向键入=改写

Your question specify Rewrite, so if this is really what you want to do, change the action type="Redirect" to type="Rewrite".

重要提示:您可能需要应用程序请求路由模块安装和设置与启用重写到不同的域的代理模式。

Important: you may need the Application Request Routing module installed and setup with the proxy mode enabled to Rewrite to a different domain.

这篇关于如何重写URL在asp.net子,而不实际创建服务器子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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