新闻资讯频道
云计算数据中心领域最新资讯

IIS 7.5通过web.config实现301重定向的方法

  1. 将不带www的域名301到www域名下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^zhuxianfei.com$" />
</conditions>
<action type="Redirect" url="http://www.zhuxianfei.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

泛解析的二级域名指向到对应的目录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <defaultDocument>
            <files>
                <clear />
                <add value="index.html" />
                <add value="index.php" />
            </files>
        </defaultDocument>
        <rewrite>
            <rules>
                <clear />
                <rule name="domain" >
                    <match url="(.*)"  />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                         
                        <add input="{HTTP_HOST}" pattern="^(.*)\.zhuxianfei\.com$" />
                        
                    </conditions>
                    <action type="Rewrite" url="{HTTP_HOST}/{R:1}" />
                </rule>
                 <rule name="api" >
                    <match url="(\w+).zhuxianfei.com/api.php?(.*)" />
                     
                    <action type="Rewrite" url="/api.php?{R:2}" appendQueryString="true" />
                </rule>
                <rule name="down">
                    <match url="(\w+).zhuxianfei.com/down-([0-9]+)-([0-9]+)-([0-9]+).html$" />
                   
                    <action type="Rewrite" url="/download.php?id={R:2}&amp;cid={R:3}&amp;n={R:4}" appendQueryString="true" />
                </rule>
                <rule name="rule56">
                    <match url="(\w+).zhuxianfei.com/fahao_(.*).html$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="/libao.php?r=libao&amp;key={R:2}" appendQueryString="false" />
                </rule>
                <rule name="rule36">
                    <match url="(\w+).zhuxianfei.com/down.html$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="/92game_down.php?n={R:1}" appendQueryString="false" />
                </rule>
                <rule name="fan" >
                    <match url="(\w+).zhuxianfei.com/(.*)" />
                     
                    <action type="Rewrite" url="/{R:1}/{R:2}" appendQueryString="true" />
                </rule>
                
                
 
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

需要注意的地方是以前httpd.ini和.htaccess支持网址中两个参数用&符号链接,在web.config中是不支持的,需要将这个符号更改为&才能正常使用。

未经允许不得转载,内容均来自网上,如有侵权请联系删除,谢谢!中网科技新闻频道 » IIS 7.5通过web.config实现301重定向的方法

分享到:更多 ()

评论 抢沙发

评论前必须登录!

 

域名、主机、云计算、服务器、机柜大带宽一站式服务平台

联系我们中网科技