happyxp 发表于 2017-11-20 10:23:57

windows IIS服务器中asp php asp.net网站如何做子目录301重定向

网站改版,生成静态页,想把生成的根目录去掉,去百度提交了站点改版,需要做301跳转。网站是个老站用aspcms做的,php的简单直接写到代码里即可,如下:

用header实现单页面的301跳转
header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: /my/m/" );
也可以用htaccess文件来实现单页面的301,规则如下
RewriteRule ^(\?(AXXX).php.*)$ "http://新的域名/$1"



如果你是用的windows+iis,也非常简单。

首先你要在IIS中已经添加HTTP重定向,如果没有需要先添加。
原网址http://www.le00.com/aspcms/news/263_2.html更改后为http://www.le00.com/news/263_2.html,首先如果没有aspcms这个文件那么先要在根目录建立一个,然后选中这个文件夹点右侧HTTP重定向。

然后重定向部分直接填根目录网址http://www.le00.com/,选择301永久重定向。点击应用即可。

最后过两个月左右时间,查看下如果百度360等搜索引擎收录已经全部更改为新网址,那么就可以删除对应的部分,大功告成!windows IIS服务器中asp php asp.net网站如何做子目录301重定向就是这么简单。
PS:最近研究发现的新的方法,不用建新的虚拟主机。
首先,推荐在IIS7.5以上使用,因为这些版本很方便安装URLRewrite,如果没有URLRewrite,先安装,具体可以参考windows2012中IIS8如何安装和使用URL重写工具-URL Rewrite。
打开网站根目录的web.config文件,把以下规则直接写在节点中就可以,如果没有web.config文件,需要在根目录新建一个,内容按照下面的完全复制即可,注意:所有配置规则都要写在节点中。网址就替换成你的网址即可。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
      <system.webServer>
                <rewrite>
                        <rules>
                                  <rule name="301Redirectwww" stopProcessing="true">
                                        <match url="(.*)" />
                                        <conditions logicalGrouping="MatchAny">
                                                <add input="{HTTP_HOST}" pattern="^xp37\.com$" />
                                        </conditions>
                                        <action type="Redirect" url="http://www.xp37.com/{R:0}" redirectType="Permanent" />
                              </rule>
                        </rules>
                </rewrite>
      </system.webServer>
</configuration>301跳转规则,如果有web.config文件中已经存在多条规则,在其中添加如下一条即可
<rules>
<rule name="301Redirectwww" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^xp37\.com$" />
</conditions>
<action type="Redirect" url="http://www.xp37.com/{R:0}" redirectType="Permanent" />
</rule>这里名称301Redirectwww可以按照自己习惯命名。
页: [1]
查看完整版本: windows IIS服务器中asp php asp.net网站如何做子目录301重定向