IIS URL重写和Web.config文件 [英] IIS URL Rewrite and Web.config

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

问题描述

我不明白有关IIS什么,但我想解决所有重定向访问者这个问题domain.com/page~~V到domain.com/page.html~~V

 <?XML版本=1.0编码=UTF-8&GT?;
<结构>
  < system.webServer>
    <&改写GT;
          < rewriteMaps>
              < RewriteMap指令名=StaticRedirects>
                  <添加键=/页值=/ page.html即可/>
              < / RewriteMap指令>
            < / rewriteMaps>
      < /重写>
  < /system.webServer>
< /结构>

一对夫妇的问题就出来了:


  1. 我不知道在哪里,甚至把文件。有一个用户的根目录,以及htdocs目录,我都试过,没有喜悦。

  2. 我甚至不知道该帐户是否能做到重写,我想找到这一点。


解决方案

1)您现有的web.config文件:您已声明重写地图..但尚未创建将使用它的任何规则。 RewriteMap指令其自身也绝对没有什么。

2)下面是你如何能做到这(它不会使用重写地图 - 只有规则,这是罚款重写的少量/重定向):

这条规则将做某个确切重写(内部重定向) /页 /page.html 。网址浏览器将保持不变。

 < system.webServer>
    <&改写GT;
        <规则与GT;
            <规则名称=SpecificRewritestopProcessing =真>
                <匹配URL =^ $页/>
                <作用TYPE =重写URL =/ page.html即可/>
            < /规则>
        < /规则>
    < /重写>
< /system.webServer>

本规则#2会做上述相同,但会做301重定向(永久重定向)其中URL将在浏览器中改变。

 < system.webServer>
    <&改写GT;
        <规则与GT;
            <规则名称=SpecificRedirectstopProcessing =真>
                <匹配URL =^ $页/>
                <作用TYPE =重定向URL =/ page.html即可/>
            < /规则>
        < /规则>
    < /重写>
< /system.webServer>

规则#3将试图为任何URL,如果有这样的文件,扩展名为.html(即在 /页它将检查执行这样的重写,如果 /page.html 存在,如果它不然后重新出现):

 < system.webServer>
    <&改写GT;
        <规则与GT;
            <规则名称=DynamicRewritestopProcessing =真>
                <匹配URL =(。*)/>
                <条件>
                    <添加输入={REQUEST_FILENAME} \\ HTML。使用MatchType =ISFILE/>
                &所述; /条件>
                <作用TYPE =重写URL =/ {R:1}的.html/>
            < /规则>
        < /规则>
    < /重写>
< /system.webServer>

I don't understand anything about IIS, but am trying to solve this problem of redirecting all visitors to domain.com/page to domain.com/page.html

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.webServer>
    <rewrite>
          <rewriteMaps>
              <rewriteMap name="StaticRedirects">
                  <add key="/page" value="/page.html" />
              </rewriteMap>
            </rewriteMaps>
      </rewrite>
  </system.webServer>
</configuration>

A couple of problems arise:

  1. I don't know where to even put the file. There is a User root directory, and an htdocs directory, I tried both, no joy.
  2. I don't even know if the account can do rewrites, I am trying to find that out.

解决方案

1) Your existing web.config: you have declared rewrite map .. but have not created any rules that will use it. RewriteMap on its' own does absolutely nothing.

2) Below is how you can do it (it does not utilise rewrite maps -- rules only, which is fine for small amount of rewrites/redirects):

This rule will do SINGLE EXACT rewrite (internal redirect) /page to /page.html. URL in browser will remain unchanged.

<system.webServer>
    <rewrite>
        <rules>
            <rule name="SpecificRewrite" stopProcessing="true">
                <match url="^page$" />
                <action type="Rewrite" url="/page.html" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

This rule #2 will do the same as above, but will do 301 redirect (Permanent Redirect) where URL will change in browser.

<system.webServer>
    <rewrite>
        <rules>
            <rule name="SpecificRedirect" stopProcessing="true">
                <match url="^page$" />
                <action type="Redirect" url="/page.html" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

Rule #3 will attempt to execute such rewrite for ANY URL if there are such file with .html extension (i.e. for /page it will check if /page.html exists, and if it does then rewrite occurs):

<system.webServer>
    <rewrite>
        <rules>
            <rule name="DynamicRewrite" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{REQUEST_FILENAME}\.html" matchType="IsFile" />
                </conditions>
                <action type="Rewrite" url="/{R:1}.html" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

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

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