最近为了网站新旧域名301重定向伤了不少脑筋,由于众所周知的原因,WordPress公园更换了域名。之前买的国内免备案VPS跑路了,只好重新找国内免备案主机。
找了两家,一家不能正常使用,申请了退款。另一家竟然是Windows主机,折腾坏了我。今天一天时间都花在域名在Windows主机的301重定向上。
下边说说Windows主机域名301整站重定向的办法:
在网站根目录创建两个文件:web.config和httpd.ini
web.config的内容是:
<?xml version=”1.0″ encoding=”UTF-8″?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name=”WWW Redirect” stopProcessing=”true”>
<match url=”.*” />
<conditions>
<add input=”{HTTP_HOST}” pattern=”^bo.moioi.com$” />
</conditions>
<action type=”Redirect” url=”https://www.moiblog.net/{R:0}” redirectType=”Permanent” />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
httpd.ini的内容是:
[ISAPI_Rewrite]
CacheClockRate 3600
RepeatLimit 32
RewriteCond Host: ^bo\.moioi\.com$
RewriteRule (.*) http\://www\.moiblog\.net$1 [I,R]
以上别忘了把域名改成自己的域名。
这种办法不分程序,只要你只是域名变了,url链接结构没变,就可以用这种办法实现老域名301跳转新域名。