IIS7以上的服务器支持通过web.config来修改配置。所以我们可以用web.config来做301重定向。
正确的代码如下,假如我从fyluo.com跳转到www.fyluo.com,那么web.config的代码可以这样写:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="www" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^fyluo\.com$" />
</conditions>
<action type="Redirect" url="http://www.fyluo.com/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
新建一个文本文档将上面的这段代码复制进去,并重命名为web.config,然后放到网站的根目录就可以了。或者直接在IIS管理器里面的-URL重写组件添加空白规则截图如下: 安装了IIS官方推出 的URL Rewrite组件之后才有效,否则是不起作用的。
模式: test.exe
条件:
{HTTP_HOST}
^www\.fyluo\.com$
重定向URL
http://www.baidu.com/test.exe
http://www.fyluo.com/test.exe
301重定向到:
http://www.baidu.com/test.exe
模式: .*
条件:
{HTTP_HOST}
^fyluo\.com$
没www301重定向到有www
http://fyluo.com --》 http://www.fyluo.com
请问 ^fyluo\.com$ 与 ^fyluo.com$ 有什么区别?就是域名里加反斜杠是什么意思?
请教一下,怎么将一篇文章跳转到另一个目录下。例如
原地址 x.com/a.htm
能否跳转到
新地址 x.com/news/a.htm
求解答。
@www.liketm.com:可以的 参考以上的模式test.exe