站长进阶

IIS配置 web.config 实现不带www跳转到带www和http跳转到https

mrye 发表于 2019-06-03 23:03

301在seo优化中起到了重要的作用,下面将讲解iis如何配置web.config不带www跳转到带www,以及http跳转到https


http 跳转到 https:

<rule name="http转https" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="off" ignoreCase="true"/>
                    </conditions>
                    <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" /></rule>

不带www 跳转到带www:

    <rule name="WWW Redirect" stopProcessing="true">
                <match url=".*" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="^mrye.xin|idc.mrye.xin$" />
                </conditions>
                <action type="Redirect" url="http://www.mrye.xin/{R:0}" redirectType="Permanent" /></rule>

其中的mrye.xin请替换成您自己的域名
完整例子:

<configuration>
    <system.webServer>
        <rewrite>
            <rules>
               <rule name="http转https" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="off" ignoreCase="true"/>
                    </conditions>
                    <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
				</rule>
				<rule name="WWW Redirect" stopProcessing="true">
					<match url=".*" />
					<conditions>
						<add input="{HTTP_HOST}" pattern="^mrye.xin|idc.mrye.xin$" />
					</conditions>
					<action type="Redirect" url="https://www.mrye.xin/{R:0}" redirectType="Permanent" />
				</rule>
            </rules>
        </rewrite>
    </system.webServer></configuration>

其中的mrye.xin请替换成您自己的域名

注意:帝国cms版本7.5以下的需要手动修改代码
步骤一:
/e/class/connect.php文件中找到eReturnDomain方法,把方法里面的内容替换成以下内容:

$domain=RepPostStr($_SERVER['HTTP_HOST'],1);
    if(empty($domain))
    {
        return '';
    }
    return ($_SERVER['HTTPS'] ? 'https':'http').'://'.$domain;

步骤二:
/e/class/connect.php文件中找到FWeReturnDomain方法,把方法里面的内容替换成以下内容:

 $domain=RepPostStr($_SERVER['HTTP_HOST'],1);
    if(empty($domain))
    {
        return '';
    }
    return ($_SERVER['HTTPS'] ? 'https':'http').'://'.$domain;


评论 (0人参与

最新评论

暂无评论
mrye


文章:233
推荐阅读
   323   
   396   
mrye   2019-06-07 22:12:20
   407   
   405