IIS 7.5 URL重写

编程入门 行业动态 更新时间:2024-10-21 19:09:44
本文介绍了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.

我需要重写我的网址:

  • 如果请求是 http:/ /mysite.co/LegacySite/page.aspx 该网址将被重写为 http:// mysite。 co / page.aspx
  • If a request is mysite.co/LegacySite/page.aspx the URL will be rewritten to 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" /> <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$" /> </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重写

本文发布于:2023-11-01 20:15:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550304.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   IIS   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!