>花语常识 >阿里云windows主机用Web.config实现全站301重定向(适用asp/asp.net/php等编码) -

阿里云windows主机用Web.config实现全站301重定向(适用asp/asp.net/php等编码)

时间:2018-1-16 16:20:30   来源:花季雨鲜花

阿里云虚拟主机后台控制面板的301重定向只适合单个页面不适合全站。
为了实现阿里云windows虚拟主机实现全站301重定向,我在网上搜索了一堆全站301重定向的方法,有的

只支持asp.net的方法没有支持asp的方法,实验了半天没有一个成功的,最后自己试着来解决,终于成功

了!此方法对所有语言的编码都能通用!具体方法如下:

复制以下代码到文本文档中
<?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="^huajiyu.com$" />
</conditions>
<action type="Redirect" url="http://www.huajiyu.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
然后改掉代码中的域名huajiyu.com和http://www.huajiyu.com/
然后把另存为Web.config,用ftp把Web.config这个文件直接上传到网站根目录下就可以了。

阿里云windows虚拟主机的伪静态方法也是写在Web.config这个文件里,此方法也是能和伪静态写法写在一起的。伪静态方法写在<rule>伪静态写法</rule>这中间就可以

阿里云伪静态写法:

<rule name="rule1" stopProcessing="true">
                    <match url="sala_([0-9,a-z]*).html" />
                    <action type="Rewrite" url="sala.php?pageno={R:1}"  />
</rule>

<rule name="rule2" stopProcessing="true">
                    <match url="other_(.*)_(.*).html" />
                    <action type="Rewrite" url="other.php?action={R:1}&amp;pageno={R:2}"  />
</rule>

                <rule name="rule2" stopProcessing="true">
                    <match url="ok_(.*)_([0-9]+)_(.*).html" />
                    <action type="Rewrite" url="ok.php?action={R:1}&amp;pageno={R:2}&amp;id={R:3}"  />
             </rule>

原创作者:网上花店