标签: url-rewrite-module

如何使用IIS7 URL重写模块重定向到应用程序根目录?

我试过了:

1)我先尝试空字符串:

<action type="Redirect" url="" redirectType="Permanent" appendQueryString="false" />
Run Code Online (Sandbox Code Playgroud)

结果:

HTTP 500.52 - URL Rewrite Module Error.
The substitution URL for the current action cannot be empty.
Run Code Online (Sandbox Code Playgroud)

2)也许我应该省略url属性:

<action type="Redirect" redirectType="Permanent" appendQueryString="false" />
Run Code Online (Sandbox Code Playgroud)

相同的结果:

HTTP 500.52 - URL Rewrite Module Error.
The substitution URL for the current action cannot be empty.
Run Code Online (Sandbox Code Playgroud)

3)ASP.NET方式怎么样:

<action type="Redirect" url="~" redirectType="Permanent" appendQueryString="false" />
Run Code Online (Sandbox Code Playgroud)

尝试重定向到{APP_ROOT}/~.

4)最后一次尝试:

<action type="Redirect" url="/" redirectType="Permanent" appendQueryString="false" />
Run Code Online (Sandbox Code Playgroud)

正如所料,它重定向到服务器的根目录......

我想找一些干净的通用解决方案.(我不能用一些具体的东西/myCurrentAppPath.)

iis iis-7 web-applications url-rewriting url-rewrite-module

7
推荐指数
1
解决办法
3360
查看次数

将IIS7 url重写部分移出web.config文件

我在我的web.config文件中创建了一个配置部分,其中包含所有重写规则,如下所示

<rewrite>
        <outboundRules>
            <rule name="OutboundRewriteCatalogURL" preCondition="ResponseIsHtml1">
                <match filterByTags="A" pattern="^(.*/)Catalog\.aspx\?Catalog=([^=&amp;]+)&amp;(?:amp;)?Title=([^=&amp;]+)$" />
                <action type="Rewrite" value="{R:1}ctlg/{R:2}/{R:3}/" />
            </rule>
            <rule name="OutboundRewriteCategoryURL" preCondition="ResponseIsHtml1">
                <match filterByTags="A" pattern="^(.*/)ProductList\.aspx\?Catalog=([^=&amp;]+)&amp;(?:amp;)?Category=([^=&amp;]+)&amp;(?:amp;)?Title=([^=&amp;]+)$" />
                <action type="Rewrite" value="{R:1}categ/{R:2}/{R:3}/{R:4}/" />
            </rule>
            <rule name="OutboundRewriteFullProductURL" preCondition="ResponseIsHtml1">
                <match filterByTags="A, Form, Img" pattern="^(.*/)Product\.aspx\?Catalog=([^=&amp;]+)&amp;(?:amp;)?Category=([^=&amp;]+)&amp;(?:amp;)?Product=([^=&amp;]+)&amp;(?:amp;)?Title=([^=&amp;]+)$" />
                <action type="Rewrite" value="{R:1}prd/{R:2}-{R:3}-{R:4}/{R:5}/" />
            </rule>
            <preConditions>
                <preCondition name="ResponseIsHtml1">
                    <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                </preCondition>
            </preConditions>
        </outboundRules>
        <rules>
            <rule name="RedirectCatalogURL" stopProcessing="true">
                <match url="^Catalog\.aspx$" />
                <conditions>
                    <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
                    <add input="{QUERY_STRING}" pattern="^Catalog=([^=&amp;]+)&amp;Title=([^=&amp;]+)$" />
                </conditions>
                <action type="Redirect" url="Catalog/{C:1}/{C:2}" appendQueryString="false" />
            </rule>
            <rule name="RewriteCatalogURL" stopProcessing="true">
                <match url="^ctlg/([^/]+)/([^/]+)/?$" …
Run Code Online (Sandbox Code Playgroud)

asp.net iis-7 url-rewriting url-rewrite-module

7
推荐指数
1
解决办法
8895
查看次数

IIS URL重写在子虚拟目录中不重定向

我在'default web site\orchard'上安装了Asp.NET Application ...可以在http:// localhost/orchard上访问,我想使用URL Rewrite.我添加了规则:

<rewrite>
    <rewriteMaps>
        <rewriteMap name="Blogger">
            <add key="/aaa" value="/tags/tag1" />
        </rewriteMap>
    </rewriteMaps>
    <rules>
        <clear />
        <rule name="Rewrite rule1 for Blogger" stopProcessing="true">
        <match url=".*" />
            <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                <add input="{Blogger:{REQUEST_URI}}" pattern="(.*)" />
            </conditions>
            <action type="Redirect" url="{C:1}" appendQueryString="false" redirectType="Permanent" />
        </rule>
    </rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)

但是当我转到http:// localhost/orchard/aaa时,会返回错误404而不是重定向到http:// localhost/orchard/tags/tag1.

当我把我的Web应用程序放在网站重定向的根文件夹中时.http:// localhost/aaa被重定向到http:// localhost/tags/tag1.

我做错了什么?

感谢帮助.

iis url-rewrite-module

7
推荐指数
0
解决办法
1000
查看次数

web.config重写以重定向html文件但排除某些文件夹

我正在尝试创建一个重写规则,将所有.html页面重定向到单个URL,不包括单个文件夹(以及所有子文件夹).我做了很多googleing并试图从类似的情况一起拼凑一些东西.

原始重写规则用于重定向所有html文件,但我试图在存在文件夹匹配时放入一个先前的规则来停止处理.

我从这开始就有用了

<rewrite>
  <rules>
    <rule name="redirect legacy html" enabled="true" stopProcessing="true">
      <match url="(.+).html$" ignoreCase="true" />
      <conditions>
        <add input="{QUERY_STRING}" pattern="^$" ignoreCase="false" />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="http://www.example.com" />
    </rule>
  </rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)

然后我添加了一个单独的规则,希望第一个停止处理,重定向不会发生

<rewrite>
  <rules>
    <rule name="ignore redirects in admin" enabled="true" stopProcessing="true">
      <match url="/script|admn/(.+).html$" ignoreCase="true" />
      <action type="None" />
    </rule>
    <rule name="redirect legacy html" enabled="true" stopProcessing="true">
      <match url="(.+).html$" ignoreCase="true" />
      <conditions>
        <add input="{QUERY_STRING}" pattern="^$" ignoreCase="false" />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="http://www.example.com" />
    </rule>
  </rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)

这继续将所有html文件重定向到www.example.com.

然后我继续尝试使用条件来排除某些目录,如下所示

<rewrite>
  <rules>
    <rule name="redirect legacy …
Run Code Online (Sandbox Code Playgroud)

regex web-config url-rewrite-module

7
推荐指数
1
解决办法
6431
查看次数

无法读取配置文件,因为它超过了最大文件大小

无法读取配置文件,因为它超出了最大文件大小.

我的错误是因为我的rewritemap.config文件大小超过250KB(带有IIS 7.5的Windows 2008 R2 SP1服务器)

configuration iis-7.5 windows-server-2008-r2 url-rewrite-module

7
推荐指数
1
解决办法
7980
查看次数

IIS URL-重写:HTTP到HTTPS

我有一些网站example.org,关于这一点我保留子网站像example.com/project1example.com/project2等.我只需要HTTP?HTTPS对某些子网站进行简单的重定向,但不想手动将其写入代码文件中.

所以我URL-Rewrite2为他找到了模块和规则:

<rewrite>
        <rules>
          <rule name="Redirect to HTTPS" stopProcessing="true">
            <match url="(.*)" />
            <conditions>
              <add input="{HTTPS}" pattern="^OFF$" />
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
          </rule>
        </rules>
      </rewrite> 
Run Code Online (Sandbox Code Playgroud)

它最多只有一个问题:它重定向http://example.com/project1https://example.com/,所以它丢失了子网站的URL部分和任何args.

如何解决这个问题?

UPD:使用此规则

    <rule name="Redirect to HTTPS" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{HTTPS}" pattern="^OFF$" />
                        </conditions>
                        <action type="Redirect" url="https://{HTTP_HOST}{UNENCODED_URL}" />
</rule>
Run Code Online (Sandbox Code Playgroud)

子网站正常重定向,但参数是重复的.http://example.com/project1?page=2变成了https://example.com/project1?page=2&page=2.我做错了什么?

iis https url-rewriting url-routing url-rewrite-module

7
推荐指数
1
解决办法
7065
查看次数

IIS URL重写否定条件不起作用

我想根据以下规则将一些页面从旧网站(oldsite.com)重定向到新网站(newsite.*):

  • 所有一级子级(/ sv,/ no,/ da等)都应该重定向到各自的对等方,即newsite.se,newsite.no,newsite.dk等.
  • 除了/page1和/ page2及其后代之外,所有其他子/后代也应该重定向到新站点的根目录.

为此,我创建了以下规则(在本例中为sv):

<rule name="Redirect /sv to .se" stopProcessing="true">
    <match url="^sv/?$" />
        <action type="Redirect" url="http://newsite.se" />
</rule>
<rule name="Redirect /sv/* except some pages" stopProcessing="true">
    <match url="^sv/.+" />
    <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_URI}" pattern="^sv/page1(.*)" negate="true" />
        <add input="{REQUEST_URI}" pattern="^sv/page2(.*)" negate="true" />
    </conditions>
    <action type="Redirect" url="http://newsite.se" />
</rule>
Run Code Online (Sandbox Code Playgroud)

第一条规则很好但不是第二规则.问题是我的否定条件似乎不起作用.当我输入oldsite.com/sv/page1时,我仍然会被重定向到newsite.se.也许我误解了否定条件是如何工作的,但是当且仅当两个条件都为真(评估为假)时,第二条规则不应该执行动作,即REQUEST_URI 与/ page1和/ page2 匹配?

iis url-rewriting url-rewrite-module

7
推荐指数
1
解决办法
8368
查看次数

IIS URL重写如何处理#锚标记

我很难找到有关如何最好地处理带锚标记的URL的任何信息,例如www.example.com/index.html#foo中的#foo

我们目前的情况是尝试使用Rewrite映射来获取带有锚标记的URL,但它正被另一个Rewrite映射所取代.

例如

 <add key="index.html#foo" value="bar1.html" />
 <add key="index.html" value="bar2.html" />

 <!-- A request to index.html#foo is being redirected to bar2.html, 
      not bar1.html as expected -->
Run Code Online (Sandbox Code Playgroud)

URL Rewrite是否在URL中包含此内容?或者可以通过其中一个变量获得?有关于此的文件吗?

(我也试过搜索"片段标识符","#""哈希""哈希标记")

iis anchor hashtag url-rewrite-module

6
推荐指数
1
解决办法
3309
查看次数

url重写模块中的自定义提供程序

我正在一个网站上开发,该网站目前在VM上托管在Azure上.现在我正在更改此网站,以便能够将其作为Azure网站运行.

现在我的问题:我正在使用IIS中的url rewrite模块和数据库提供程序,它在VM中运行良好.使用数据库提供者,网站的用户可以创建自己的简单重写规则.

但是当我将我的网站上传为Azure网站并访问数据库中指定的网址时,我收到错误消息:

"由于发生内部服务器错误,无法显示页面."

这是我目前使用的日志配置:

<rewrite>
  <rules configSource="RewriteInbound_Live.config" />
  <outboundRules configSource="RewriteOutbound_Live.config" />
  <providers>
    <provider name="DB" type="DbProvider, Microsoft.Web.Iis.Rewrite.Providers, Version=7.1.761.0, Culture=neutral, PublicKeyToken=0545b0627da60a5f">
      <settings>
        <add key="ConnectionString" value="*****" />
        <add key="StoredProcedure" value="sp_GetRewrittenUrl" />
        <add key="CacheMinutesInterval" value="60" />
      </settings>
    </provider>
  </providers>
</rewrite>
Run Code Online (Sandbox Code Playgroud)

我打开了Web服务器日志记录,它没有给我任何信息,我启用了应用程序日志记录,但也没有给我任何信息.

我的问题是,是否可以在Azure中使用自定义提供程序用于url rewite模块,这可以通过其他方式实现吗?

azure url-rewrite-module

6
推荐指数
1
解决办法
477
查看次数

UrlRewrite条件基于自定义HTTP标头

我正在尝试在UrlRewrite中配置一个有两个条件的规则:

  • HTTP标头" HTTP_HOST "需要匹配某个域(api.contoso.com)
  • 自定义HTTP标头" x-app-version "需要出现在HTTP请求中

根据这些信息,我想在后端重定向到不同版本的api.

问题 规则在第一个条件下的行为与预期相同.当HTTP_HOST与api.contoso.com匹配时,它就会启动.但是,它会忽略我的自定义标题"x-app-version".

假设 因此,我担心UrlRewrite条件只能与下拉列表中有限的一组预定义HTTP头一起定义(HTTP_HOST,REMOTE_ADDRESS,REMOTE_HOST,...)

问题 假设是正确的还是应该是可能的?配置或其他方法中的错误是否有基于自定义http头的条件?

<rule name="ARR_test2" enabled="false">
  <match url="(.*)" />  
  <conditions>
    <add input="{HTTP_HOST}" pattern="api.contoso.com" />
    <add input="{x-app-version}" pattern="1" />
  </conditions>
  <action type="Rewrite" url="https://FARM_apiv1/{R:0}" />
</rule>
Run Code Online (Sandbox Code Playgroud)

iis url-rewriting url-rewrite-module

6
推荐指数
1
解决办法
4829
查看次数