美国godaddy主机win IIS空间301转向
如何实现网站域名301重定向呢,网上给出的方法有很多:
Apache服务器的.htaccess实现301重定向
RewriteEngine on
RewriteCond %{http_host} ^ifenwen.com [NC]
RewriteRule ^(.*)$ http://www.ifenwen.com/$1 [L,R=301]
IIS服务器实现301重定向:
用ASP/PHP实现301重定向:
ASP:
Response.Status=”301 Moved Permanently”
Response.AddHeader “Location”,”http://www.ifenwen.com/”
Response.End
PHP:
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location:http://www.ifenwen.com/”);
exit();
可惜这些方法对我都不试用,因为是win主机,所以无法设置.htaccess文件;因为不是独立主机,所以无法进行IIS设置;而对于asp/php方法,也尝试失败。
突然想到以前设置WordPress固定链接的时候用到一个文件:web.config。而所有和链接修改的设置都是在这里面,那要实现301重定向,把不带www的ifenwen.com重定向到带www的www.ifenwen.com是不是也可以在这里面设置呢?有了这样一个思路,参考原先web.config文件里书写规则,便完美实现了Godaddy免费Win主机301重定向。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="wordpress" patternSyntax="Wildcard">
<match url="*"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="index.php"/>
</rule>
<rule name="WWW Redirect" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^ifenwen.com$" />
</conditions>
<action type="Redirect" url="http://www.ifenwen.com/{R:0}"
redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
其中红色部分便是新加代码用以实现301重定向,其余部分不动。
做好301重定向之后,可以检测一下成功与否:
