不带www跳转到www,http跳转到https

所属栏目:建站技术 更新时间:2023-03-23 点击: 文章来源:https://www.sznest.net/jzjs/7571.html

一:windows操作系统,在网站根目录下,新建web.config这个文件
1:不带www跳转到www代码示例
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="to www" stopProcessing="true">
          <match url=".*" />
          <conditions>
              <add input="{HTTP_HOST}" pattern="^sznest\.net$" />
          </conditions>
          <action type="Redirect" url="http://www.sznest.net/{R:0}" />
        </rule>
        <rule name="http to 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>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

2:http跳转到https代码示例
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="http to 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>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

也可以用下面的
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="http to https" stopProcessing="true">
          <match url="^(.*)$" ignoreCase="false" ></match>
          <conditions logicalGrouping="MatchAll">                       
            <add input="{HTTP_FROM_HTTPS}" pattern="^on$" negate="true" ></add>  
          </conditions>
          <action type="Redirect" url="https://www.顶级域名/{R:1}" redirectType="Permanent" ></action>
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

3:不带www跳转到www,http跳转到https代码示例
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="to www" stopProcessing="true">
          <match url=".*" />
          <conditions>
              <add input="{HTTP_HOST}" pattern="^sznest\.net$" />
          </conditions>
          <action type="Redirect" url="https://www.sznest.net/{R:0}" />
        </rule>
        <rule name="http to 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>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

二:Linux操作系统,在网站根目录下,新建.htaccess这个文件
1:不带www跳转到www代码示例
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^sznest.net [NC]
    RewriteRule ^(.*)$ http://www.sznest.net/$1 [L,R=301]
</IfModule>

2:http跳转到https代码示例
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R=301,L]
</IfModule>

3:不带www跳转到www,http跳转到https代码示例
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^sznest.net [NC]
    RewriteRule ^(.*)$ https://www.sznest.net/$1 [L,R=301]
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.sznest.net/$1 [L,R=301]
</IfModule>

相关阅读

数据库操作工具类SqlHelper

classSqlHelper{public$conn;public$host=&quot;localhost&quot;;public$username=&quot;root&quot;;public$password=&quot;root&quot;;public$dbname=&quot;mydb&quot;;publicfunction__constr…

了解详情 >>

用火狐打开百度一直加载s1.bdstatic.com的解决办…

一直用火狐浏览器,火狐浏览器插件多,很合适网页开发人员使用,以前一直用的好好的,但是今天使用的时候突然发现没有以前好用了,打开百度的官网一直很卡,通过FIREBGU发现在打开百度官网的时候一直会加载s1.bdstatic.com这个网站,无语,怎么打开百度的官网还需要链接s1.bdstatic.com这个网站这个网站吗?难道是百度被黑了,或者是自己的浏览器被…

了解详情 >>

帝国CMS-采集关键的经验总结

采集关键的几个步骤一:先建好栏目二:增加采集节点(需要选择栏目)三:录入节点名称四:如果有很多页,只需录入采集页面地址方式二中的内容地址为https://www.sznest.net/news.asp?big_class_id=3&amp;page=[page]页码从1到多少页之间、间隔倍数为1(这个多少页即被采集的网站的实际页数,注意这里修改后,在采集页面…

了解详情 >>

过滤html标签与标签之间的空格以及标签和内容之间的空格

&lt;?phpob_start();?&gt;&lt;pid=&quot;name&quot;&gt;与左边的右尖括号有一个空格喔与右边的左尖括号有两个空格喔&lt;/a&gt;&lt;p&gt;与左边的右尖括号有三个空格喔&lt;/a&gt;&lt;p&gt;只与右边的左尖括号有四空格喔&lt;/a&gt;&lt;p&gt;两边没有空格但是中间有空格喔&…

了解详情 >>

如何将程序添加到右键菜单中?

方法一:在HKEY_CLASSES_ROOT*shell下面添加sublime_textCommand,修改Command项的默认值的数据数值为&quot;D:我的文档sublimetext3sublime_text.exe&quot;&quot;%1&quot;改了之后此方法你会发现不管选择什么类型的文件都会出现在右键菜单中方法二:修改HKEY_CLASS…

了解详情 >>

小程序倒计时wxml与js

小程序倒计时jsPage({data:{windowHeight:654,maxtime:&quot;&quot;,isHiddenLoading:true,isHiddenToast:true,dataList:{},countDownDay:0,countDownHour:0,countDownMinute:0,countDownSecond:0,},/…

了解详情 >>

Copyright @ 2008-2019   www.sznest.net   All rights reserved  网巢网是一家专业为企业提供免费建站、自助建站的模板建站公司     友情链接:香港张元洪律师行   

微信

移动端

客服

顶部