用IIS Rewrite规则来重新定向新域名

来源:互联网 发布:靠垫 知乎 编辑:程序博客网 时间:2024/06/05 16:43

1.3版的域名重定向:

# For ISAPI_Rewrite 1.3 重定向域名
#重定向ezxw.net
RewriteCond Host: ^ezxw/.net$
RewriteRule (.*) http/://lady68/.com1 [I,R]
#重定向 www.ezxw.net


RewriteCond Host: ^test/.ezxw/.net$
RewriteRule (.*) http/://www/.ezxw/.net$1 [I,R]

这里我们要将bbs.ezxw.net重定向 www.ezxw.net


由于ISAPI Rewrite现在使用较多的有两个版本2.x版跟3.x版
那么就把两个版本的规则都写出来,3.0版本是不兼容2.0的规则的,只是有提供规则转换器,导入就可以转换了。

# For ISAPI_Rewrite 2.x
RewriteCond Host: ^ezxw/.net$
RewriteRule (.*) http/://lady68/.com$1 [I,RP]
RewriteCond Host: ^www/.ezxw/.net$
RewriteRule (.*) http/://www/.lady/.com$1 [I,RP]

# For ISAPI_Rewrite 3.x
RewriteCond %{HTTP:Host} ^ezxw/.net$
RewriteRule (.*) http/://lady68/.com$1 [NC,R=301]
RewriteCond %{HTTP:Host} ^www/.lady68/.com$
RewriteRule (.*) http/://www/.ezxw/.net$1 [NC,R=301]

说明:[I,RP]:I表示忽略大小写,RP表示使用301转向,以上都是整个域名重定向。

单一页面重定向的写法,将根目录下的1.html重定向到http://www.ezxw.net/index.html

# For ISAPI_Rewrite 2.x
RewriteRule ^/1.html$ http://www.ezxw.net/index.html [I,O,RP,L]

# For ISAPI_Rewrite 3.x
RewriteRule ^/1.html$ http://www.ezxw.net/index.html [NC,L,R=301,O]
说明:O表示对URL进行标准化,L表示Last Rule,最后一条规则,也就是后面的重写规则对他不起作用,防止被其他匹配的规则再次重写。这里的路径可以是相对路径也可以是绝对路径。

原创粉丝点击